Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Access Parent Statusbar from a child

0.00/5 (No votes)
30 Nov 2004 1  
Update the parent's status bar panel(s) from a child MDI form

Introduction

Like many others I have been searching for a way to access the statusbar on a MDI parent form from a child in the simplest and least code intensive manner.

Again, like most others I have found that this appears to be like the Holy Grail .... someone knows but is not telling.

Well after wasting my time on searches and finding all kinds of advice on reflection, events etc I decided to do some coding - hacking in the old sense.

The following code works quite nicely, but has only been tested on an XP Pro system using VSNet2K3.

Steps to do

Assuming a status bar with 1 panel ....

  • In the child form add the following variable:
    public System.Windows.Forms.StatusBarPanel pfrm_sbp1 = null;
  • Add the following code where you want to update the statusbar PANEL:
    pfrm_sp1.Text = "How did he do that?";
  • In the parent form when you create the child, set the reference:
    Form2 newMDIChild = new Form2();
    newMDIChild.MdiParent = this;
    newMDIChild.pfrm_sp1 = statusBarPanel1;
    newMDIChild.Show();

Of course, you could do this via other more secure mechanisms (please do) - make the reference variable private with get/set functions, perhaps make it an array of panel references, but you get the basic idea now don't you.

Anything more pervasive would benefit from a more comprehensive and better design here's an excellent article (link) to guide you if you decide to go further down into the internals of inter window communications.


License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here