Update status bar of MDI parent from child forms in windows application

Hi,
I need to know the best way of coding that will write to status bar panels of mdi parent from child forms.

Thanks in advance!
CoolcldAsked:
Who is Participating?
 
J_MakConnect With a Mentor Commented:
Oh ok.... i only had a guess at it... I have just realised that it may not work. I think you should have a property in your Parent class like so:

   Shared WithEvents stsMain As System.Windows.Forms.StatusBar

   Friend ReadOnly Property GetStatusBar() As StatusBar
        Get
            GetStatusBar= stsMain
        End Get
    End Property

In your child form you can do this to access the parent's status bar:

Me.MdiParent.GetStatusBar.Panels(0).Text = strMessage

Hope that works now.
0
 
123654789987Commented:
In your MDI parent class u can have a static method, that updates the Status bar text. Then u can call this static method from the Child forms
0
 
CoolcldAuthor Commented:
Hi,
Thanks for the comment. Do I need to share the status bar control also? Because I am not able to access 'Friend' type control inside shared method.

Thanks in advance!
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
J_MakCommented:
To obtain the Mdi Parent of the a child form, try the following:

'this is in the child form
Me.MdiParent.StatusBar1.Text = "I'm a child"

That will do it for you. Cheers.
0
 
CoolcldAuthor Commented:
Hi 123654789987,
How to code a static method in windows application? I used shared in place of static. Is it correct?

Method:
Public Shared Sub WriteStatus(ByVal strMessage As String)
            stsMain.Panels(0).Text = strMessage
End Sub

Staus bar Control:
Shared WithEvents stsMain As System.Windows.Forms.StatusBar

This works. But need to know whether it is the best way of doing.
0
 
J_MakCommented:
Can't you just perform this command:

Me.MdiParent.StatusBar1.Panels(0).Text = strMessage

You wouldn't need to write your own function since you can access the parent's status bar using properties.




0
 
CoolcldAuthor Commented:
Hi  J_Mak,
Iam not able to access statusbar of mdiparent from child.
 i.e.Me.MdiParent.stsMain is not accepted. Did you tried this and worked for you? Please let me know.
0
 
armoghanCommented:
StatusBar1 seems to be public in J_Mak  post
0
 
armoghanCommented:
and you need to cast it to the name of your MDI parent
0
 
armoghanCommented:
something like this in C#
((MyParentForm)this.MdiParent).stsMain
0
 
wguerramConnect With a Mentor Commented:
You have to change the Modifiers property of the status bar to public in order to have access.

this property can be changed at design time.
0
 
CoolcldAuthor Commented:
Hi,
I made the status bar as 'public' and added the below code

Me.MdiParent.GetStatusBar.Panels(0).Text = strMessage

It works fine. Thanks.
0
 
J_MakCommented:
no worries, glad i could help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.