Click here to Skip to main content
Licence CPOL
First Posted 30 Nov 2004
Views 37,100
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  
dear limey, i already have tested this approach in my code, and it is working perfectly.
 
Regarding ur points
 
1-when a child opens up under mdi, an instance of mdi already exists, so u just need to access the static variable of that instance, no need to create an object.
 
2-yes that is true that we have to remove all the "this" indexers for that variable, but what is the harm in doing this ?
 
3-there is no need of anyother change. all work fine.
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  
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
Web02 | 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