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

Access Parent Statusbar from a child

By LimeyRedneck | 30 Nov 2004
Update the parent's status bar panel(s) from a child MDI form
2 votes, 20.0%
1
1 vote, 10.0%
2

3
1 vote, 10.0%
4
6 votes, 60.0%
5
3.64/5 - 10 votes
μ 3.64, σa 3.15 [?]

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 Pinmemberginojmg2:16 27 Nov '11  
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  
Hi,i m using vs 2005 & working in windows application of vb.net. the scenario is I m using MDIForm. From parent forms, i open a child form. on page load data is filled in datagridview named empgrid. I m trying to set mdiparent of a relevant form as nothing. i m using the code
 
If EmpGrid.IsCurrentRowDirty Then
If IsDBNull(CType(sender, DataGridView).Rows(e.RowIndex).Cells(0).Value) Then
Me.MdiParent = Nothing
MessageBox.Show("Please inset the value")
e.Cancel = True
End If
End If
But it gives me the exception "Operation did not succeed because the program cannot commit or quit a cell value change"
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  
QuestionWhat to do? Pinmembertomek13m3:24 14 May '07  
AnswerRe: 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    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.120210.1 | Last Updated 30 Nov 2004
Article Copyright 2004 by LimeyRedneck
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid