Click here to Skip to main content
6,595,854 members and growing! (18,267 online)
Email Password   helpLost your password?
Languages » C# » Windows Forms     Intermediate License: The Code Project Open License (CPOL)

Access Parent Statusbar from a child

By LimeyRedneck

Update the parent's status bar panel(s) from a child MDI form
C#, VC7.1, .NET, WinXP, MFC, VS.NET2003, Dev
Posted:30 Nov 2004
Views:28,350
Bookmarked:17 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
9 votes for this article.
Popularity: 3.42 Rating: 3.58 out of 5
2 votes, 22.2%
1
1 vote, 11.1%
2

3
1 vote, 11.1%
4
5 votes, 55.6%
5

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


Member
A conforming non-conformist (yes they exist), I do contract work as a Technical Analyst and solution architect. Currently mentoring my local High School Robotics team in Programming and Web design.

I am addicted to the Atlanta Braves, my two boys and my wife, in various orders based on the circumstances and context.

Occupation: Web Developer
Location: United States United States

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh)FirstPrevNext
GeneralThanks Pinmemberpintamono8:02 29 Dec '08  
Generalthe simplest way to access the status bar of the mdi parent PinmemberSalman Farooq3:01 13 Mar '08  
GeneralRe: the simplest way to access the status bar of the mdi parent PinmemberLimeyRedneck9:10 15 Mar '08  
GeneralRe: the simplest way to access the status bar of the mdi parent PinmemberMember 397851719:28 20 Mar '08  
Questionhow can we set MDI.Parent of relevant form as nothing Pinmembermshariq2:01 14 Nov '07  
AnswerRe: how can we set MDI.Parent of relevant form as nothing PinmemberLimeyRedneck14:52 28 Nov '07  
GeneralRe: how can we set MDI.Parent of relevant form as nothing Pinmembermshariq19:54 28 Nov '07  
GeneralWhat to do? Pinmembertomek13m3:24 14 May '07  
GeneralRe: What to do? PinmemberLimeyRedneck17:58 14 May '07  
GeneralThanks PinmemberDrPete23:39 23 Apr '07  
GeneralRe: Thanks PinmemberLimeyRedneck7:42 24 Apr '07  
GeneralSmartly Done Pinmemberdavelalit0:37 16 Sep '06  
GeneralWell done!!! PinmemberNikola Knezevic0:33 18 Aug '06  
GeneralThank You much Pinmembermarek.pastorek1:03 23 May '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 30 Nov 2004
Editor: Nishant Sivakumar
Copyright 2004 by LimeyRedneck
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project