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;
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.