Click here to Skip to main content
Licence CPOL
First Posted 30 Nov 2004
Views 37,093
Bookmarked 21 times

Access Parent Statusbar from a child

By | 30 Nov 2004 | Article
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

LimeyRedneck

Technical Lead

United States United States

Member

A conforming non-conformist (yes they exist), currently employed as a Technical Analyst and solution architect in the financial sector.
 
I am addicted to the Atlanta Braves, my two boys and my wife in various orders based on the circumstances and context.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberginojmg1:16 27 Nov '11  
GeneralThanks Pinmemberpintamono7:02 29 Dec '08  
Generalthe simplest way to access the status bar of the mdi parent PinmemberSalman Farooq2:01 13 Mar '08  
GeneralRe: the simplest way to access the status bar of the mdi parent PinmemberLimeyRedneck8:10 15 Mar '08  
GeneralRe: the simplest way to access the status bar of the mdi parent PinmemberMember 397851718:28 20 Mar '08  
Questionhow can we set MDI.Parent of relevant form as nothing Pinmembermshariq1:01 14 Nov '07  
AnswerRe: how can we set MDI.Parent of relevant form as nothing PinmemberLimeyRedneck13:52 28 Nov '07  
GeneralRe: how can we set MDI.Parent of relevant form as nothing Pinmembermshariq18:54 28 Nov '07  
QuestionWhat to do? Pinmembertomek13m2:24 14 May '07  
AnswerRe: What to do? PinmemberLimeyRedneck16:58 14 May '07  
Assuming that each child has a dedicated panel, then just assign the relevant panel reference
 
. . .
newMDIChild1.pfrm_sp1 = statusBarPanel1;
. . .
newMDIChild2.pfrm_sp1 = statusBarPanel2;
. . .

 
On the other hand, if each child adds a panel when created, add the panel to the parent and assign the new reference. Be careful of how many of these you end up with and, of course, adding a panel dynamically like this needs additional management of the panel collection.
something like this ...

StatusBarPanel panel2 = new StatusBarPanel();
panel2.width = ..
panel2.MinWidth = ..
statusBar1.Panels.Add(panel2);
 
Form2 newMDIChild = new Form2();
newMDIChild.MdiParent = this;
newMDIChild.pfrm_sp1 = statusBar1.panels(statusBar1.panels.indexOf(panel2));
newMDIChild.Show();
. . .

(see http://msdn2.microsoft.com/en-us/library/system.windows.forms.statusbar.statusbarpanelcollection(vs.80).aspx for help in working with the statusbarpanels collection)
 
Personally, I would try to design the application to support the first method (fixed number of panels) and assign/deassign them to the children as necessary, changing the background color when the child is active, and have a maximum number of children (say 4).
 
If this isn't possible, or you absolutely need LOTS of children, then I would minimize the width of all but the panel for the active child, and use icons or color to indicate if a message is posted to an inactive panel. Hovering on such a panel would show a tooltip with the panel textual content (I haven't tried this tooltip idea and have not the time to - if you try this let me know if it works as expected).
 
BTW, I haven't had an opportunity to try this technique with the new StatusStrip - maybe someday I'll have time to redo the article to include Net 2.0 controls.
 

 

 
Nothing is impossible, we just don't know the way of it yet.

GeneralThanks PinmemberDrPete22:39 23 Apr '07  
GeneralRe: Thanks PinmemberLimeyRedneck6:42 24 Apr '07  
GeneralSmartly Done Pinmemberdavelalit23:37 15 Sep '06  
GeneralWell done!!! PinmemberNikola Knezevic23:33 17 Aug '06  
GeneralThank You much Pinmembermarek.pastorek0:03 23 May '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120529.1 | Last Updated 30 Nov 2004
Article Copyright 2004 by LimeyRedneck
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid