Click here to Skip to main content
15,889,281 members
Articles / Desktop Programming / MFC
Article

Access Parent Statusbar from a child

Rate me:
Please Sign up or sign in to vote.
4.00/5 (10 votes)
30 Nov 2004CPOL1 min read 60.3K   2   24   15
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:
    C#
    public System.Windows.Forms.StatusBarPanel pfrm_sbp1 = null;
  • Add the following code where you want to update the statusbar PANEL:
    C#
    pfrm_sp1.Text = "How did he do that?";
  • In the parent form when you create the child, set the reference:
    C#
    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)


Written By
Architect Synovus Financial
United States United States
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.

Comments and Discussions

 
GeneralMy vote of 5 Pin
ginojmg27-Nov-11 1:16
ginojmg27-Nov-11 1:16 
GeneralThanks Pin
pintamono29-Dec-08 7:02
pintamono29-Dec-08 7:02 
Generalthe simplest way to access the status bar of the mdi parent Pin
Salman Farooq13-Mar-08 2:01
Salman Farooq13-Mar-08 2:01 
GeneralRe: the simplest way to access the status bar of the mdi parent Pin
LimeyRedneck15-Mar-08 8:10
professionalLimeyRedneck15-Mar-08 8:10 
GeneralRe: the simplest way to access the status bar of the mdi parent Pin
Member 397851720-Mar-08 18:28
Member 397851720-Mar-08 18:28 
Questionhow can we set MDI.Parent of relevant form as nothing Pin
mshariq14-Nov-07 1:01
mshariq14-Nov-07 1:01 
AnswerRe: how can we set MDI.Parent of relevant form as nothing Pin
LimeyRedneck28-Nov-07 13:52
professionalLimeyRedneck28-Nov-07 13:52 
GeneralRe: how can we set MDI.Parent of relevant form as nothing Pin
mshariq28-Nov-07 18:54
mshariq28-Nov-07 18:54 
QuestionWhat to do? Pin
tomek13m14-May-07 2:24
tomek13m14-May-07 2:24 
AnswerRe: What to do? Pin
LimeyRedneck14-May-07 16:58
professionalLimeyRedneck14-May-07 16:58 
GeneralThanks Pin
DrPete23-Apr-07 22:39
DrPete23-Apr-07 22:39 
GeneralRe: Thanks Pin
LimeyRedneck24-Apr-07 6:42
professionalLimeyRedneck24-Apr-07 6:42 
GeneralSmartly Done Pin
davelalit15-Sep-06 23:37
davelalit15-Sep-06 23:37 
GeneralWell done!!! Pin
User 91483317-Aug-06 23:33
User 91483317-Aug-06 23:33 
GeneralThank You much Pin
marek.pastorek23-May-06 0:03
marek.pastorek23-May-06 0:03 

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

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