MDIParent Statusbar

P

Paul Remblance

I have tried several approaches to update the mdiparent status bar from a
module.

A bit complicated as the path could be:
Parent -> Child1 -> dialog1 -> module.sub (long process)
Parent -> Child2 -> dialog2 -> module.sub (long process)
Parent -> Child3 -> dialog3 -> module.sub (long process)
etc. (being a dialog only one process can run at a time)

Tried:

In the module:
dim frm as new Parent
frm.statusbar.page1.text = "something"

Even tried in the parent:
Public Sub UpdateStatusbar(byval strText as String)
statusbar.page1.text = "something"
End Sub
But sub UpdateStatusbar cannot be seen in Module1

Any ideas or can it not be done?

Thanks, Paul
 
K

Ken Tucker [MVP]

Hi,

You need a reference to the form. If you only have one
instance of the form running at once you can add a shared property to the
form to get reference. Add the follow code to the mdi parent form. Change
frmMdiParent with your forms name

Add to the forms new procedure

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frm = Me
End Sub

Add to the forms dispose procedure

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
frm = Nothing
MyBase.Dispose(disposing)
End Sub


Add the following code to the form

Private Shared frm As frmMDIParent

Public Shared ReadOnly Property DefInstance() As frmMDIParent
Get
If frm Is Nothing Then frm = New frmMDIParent
Return frm
End Get
End Property


To use

Module test

Public Sub changeStatus()
frmMDIParent.DefInstance.StatusBar1.Text = "Live from module"
End Sub
End Module


Ken
 
P

Paul Remblance

Many thanks, Paul

Ken Tucker said:
Hi,

You need a reference to the form. If you only have one
instance of the form running at once you can add a shared property to the
form to get reference. Add the follow code to the mdi parent form.
Change frmMdiParent with your forms name

Add to the forms new procedure

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frm = Me
End Sub

Add to the forms dispose procedure

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
frm = Nothing
MyBase.Dispose(disposing)
End Sub


Add the following code to the form

Private Shared frm As frmMDIParent

Public Shared ReadOnly Property DefInstance() As frmMDIParent
Get
If frm Is Nothing Then frm = New frmMDIParent
Return frm
End Get
End Property


To use

Module test

Public Sub changeStatus()
frmMDIParent.DefInstance.StatusBar1.Text = "Live from module"
End Sub
End Module


Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top