Referencing a control on MDI Parent

  • Thread starter Thread starter George
  • Start date Start date
G

George

I am just moving from VB to C# so I hope this isn't going to be too
obvious... I am trying to reference a control (status bar) on an MDI parent
from a child form and can't seem to get the syntax correct.

I have made the control public on the parent form yet get this to work.

Can anyone point me in the right directions?


Thanks
 
George,

You can't just use the name of the type of the parent form. In VB, a
static instance with the name of the type was exposed.

If I am right, you probably are using the MdiParent property on the form
to get the parent. This will have to be cast to the type of the parent
form, and then you should be able to access it, like this:

// Get the parent control.
MyParentForm pobjForm = (MyParentForm) this.MdiParent;

// Access the control.
TextBox pobjTextBox = pobjForm.TextBox1;

Hope this helps.
 
Helps a bunch! Thanks


Nicholas Paldino said:
George,

You can't just use the name of the type of the parent form. In VB, a
static instance with the name of the type was exposed.

If I am right, you probably are using the MdiParent property on the form
to get the parent. This will have to be cast to the type of the parent
form, and then you should be able to access it, like this:

// Get the parent control.
MyParentForm pobjForm = (MyParentForm) this.MdiParent;

// Access the control.
TextBox pobjTextBox = pobjForm.TextBox1;

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

George said:
I am just moving from VB to C# so I hope this isn't going to be too
obvious... I am trying to reference a control (status bar) on an MDI parent
from a child form and can't seem to get the syntax correct.

I have made the control public on the parent form yet get this to work.

Can anyone point me in the right directions?


Thanks
 
Back
Top