MDI Children

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Yesterday, I posted a question about accessing controls on a child form. I had trouble understanding it. I am NOT rewriting this program, and need a way to work this out the way it is. Here is exactly what I'm dealing with: I have my main form(Form1), which contains a third-party main-menu and two third-party toolbars. Then there is its child form(frmTextControl) which contains a third-party text control set to fill docking. That is the only control on that form. When I have multiple instances of the child form(frmTextControl), I want to beable to assign the font of the active textcontrol ONLY. This would require access to the active MDI child form. I need to know how to name each intance of the child form, and to be able to have access to the active instance of the child form. And again, I don't want any alternate methods of accomplishing this, but how to do it with the setup I currently have. Thank You!
 
I noticed while in Form1, I could do "Form1.ActiveMdiChild" but it did not contain the control that I wanted. Is it possible to have the control listed within "Form1.ActiveMdiChild. Note: The textcontrol's modifier is set to public

----- I wrote: ----

Yesterday, I posted a question about accessing controls on a child form. I had trouble understanding it. I am NOT rewriting this program, and need a way to work this out the way it is. Here is exactly what I'm dealing with: I have my main form(Form1), which contains a third-party main-menu and two third-party toolbars. Then there is its child form(frmTextControl) which contains a third-party text control set to fill docking. That is the only control on that form. When I have multiple instances of the child form(frmTextControl), I want to beable to assign the font of the active textcontrol ONLY. This would require access to the active MDI child form. I need to know how to name each intance of the child form, and to be able to have access to the active instance of the child form. And again, I don't want any alternate methods of accomplishing this, but how to do it with the setup I currently have. Thank You!
 
You can cast the ActiveMdiChild property. Let's assume you child forms are
*always* of type frmTextControl.

((frmTextControl)Form1.ActiveMdiChild).MySuperDooperDockingControl

Bill English said:
I noticed while in Form1, I could do "Form1.ActiveMdiChild" but it did
not contain the control that I wanted. Is it possible to have the control
listed within "Form1.ActiveMdiChild. Note: The textcontrol's modifier is
set to public.
----- I wrote: -----

Yesterday, I posted a question about accessing controls on a
child form. I had trouble understanding it. I am NOT rewriting this
program, and need a way to work this out the way it is. Here is exactly
what I'm dealing with: I have my main form(Form1), which contains a
third-party main-menu and two third-party toolbars. Then there is its child
form(frmTextControl) which contains a third-party text control set to fill
docking. That is the only control on that form. When I have multiple
instances of the child form(frmTextControl), I want to beable to assign the
font of the active textcontrol ONLY. This would require access to the
active MDI child form. I need to know how to name each intance of the child
form, and to be able to have access to the active instance of the child
form. And again, I don't want any alternate methods of accomplishing this,
but how to do it with the setup I currently have. Thank You!
 
Ok, here's an example. Let's say you have a button on Form1 called myButton
with an event handler called myButton_Click.

private void myButton_Click(object sender, EventArgs e)
{
TextControl tc = ((frmTextControl)this.ActiveMdiChild).myTextControl;
//This will be the name of the control that you have the public access
modifier on.
//Now do whatever you want with tc.
}


Bill English said:
// You can cast the ActiveMdiChild property. Let's assume you child forms are
// *always* of type frmTextControl.
//
// ((frmTextControl)Form1.ActiveMdiChild).MySuperDooperDockingControl
//

My child form is always frmTextControl. I tried putting your code into
mine, but I don't know how to implement it. Could you tell me what form to
place it in, and in what context? Thank You Very Much!
 
You can also use the "as" operator to do the cast. It doesn't raise an
exception on failure, instead it returns null.


private void myButton_Click(object sender, EventArgs e)
{
frmTextControl tc = this.ActiveMdiChild as frmTextControl;

//Again you can Now do whatever you want with tc.

if( tc != null )
{
tc.myFunc();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top