Set control properties on MDI parent

stustarz

Junior Contributor
Joined
Jan 10, 2003
Messages
246
Location
Earth
I am using an MDI in my application which has a progress bar on the bottom. I would like to control this progress bar from within the child MDI's. E.g Click button on Child FOrm 1 that loads child form 2 - progress bar on MDI parent shows progress.

Thanks for any help you give.
 
You'll need to somehow get access to that control or to a method/property that can set the control. There's a couple of ways to do this. The easiest is probably to pass a reference to *exact* type of MDIForm to the child forms. So if your MDI form's class is named "frmMain", then add a parameter to the contstructor of Form1 like so (C#):
Code:
private frmMain myParent;

public Form1 (frmMain myParent)
{
    this.myParent = myParent;
}

private void btnClick(...)
{
    myParent.progressBar1.Value = 50;
}

The above assumes that the modifier for frmMain's progress bar is set to Public instead of the default private.

When frmMain creates an instance of Form1, it would use something like this:
Code:
private void mnuClick(...)
{
    // Pass "this" to the constructor of Form1 so
    // that it has a reference and can reach progressBar1
    Form1 f = new Form1(this);
    f.MDIParent = this;
    f.Show();
}

-Nerseus
 
Back
Top