MDI Parent call MID Child events, methods

  • Thread starter Thread starter Waleed Seada
  • Start date Start date
W

Waleed Seada

Hi all
What need to be done to get the MDI parent call his MDI children Events,
methods

Thanks in advance
/WS
 
Hi,

If you want MDI parent call its child method then give that method
a "public" accesor.

I'm not really sure what you want to call child event for?
Don't you want to add handle to that child's event?
If so, then i don't see any problem, e.g. add event handler in child
initializing block.

If i missed somethig then don't affraid to feedback.

regards
Marcin
 
Yes, will be great:
Would you like to explain more detail about how to define this event,
and to work with

Thanks, regards
/WS
 
Waleed Seada said:
Hi all
What need to be done to get the MDI parent call his MDI children Events,
methods

Thanks in advance
/WS

Maybe you mean such like this:


MdiClientForm f = new MdiClientForm();
f.Show();

// Add Handler when you create a new child form (for example closed handler)
f.Closed += new EventHandler(MdiClientForm_Closed);


// Handle Events here
private void MdiClientForm_Closed(object sender, System.EventArgs e)
{
}
 
If you want to call methods or respond to events that are specific to
the children form classes (outside of the base set for Forms) it may
help to define an abstract class for the children to inherit from or an
interface for them to mix in. This way you can iterate through the
children and to call methods or create more generic routines for
assigning event handlers to new child forms as they are created at
runtime. I don't know if this is exactly what you are trying to do,
but if it is I hope it helps.

-Dan Shanyfelt
 
I understand what "Torsten" said, Could you illustrate more detail, please
Thanks
Waleed Seada
 
Hi,

You should explain what you want to achieve, first.
If you don't know how to define your own event then you should
read some docs or C# books to learn how it works.

Marcin
 
I already did, what I want to do is to implement what I have read, and with
examples, I will be able to decide
I want to create a custom treeview control, then add some events and methods
for it to work

How simply by defining one method and one event I can get it to work, can
you help me in this please

Thanks for your help
Waleed Seada
 
-to make the "abstract" form:

public class abForm : System.Windows.Forms.Form

//public abstract class abForm : System.Windows.Forms.Form
//making this a real abstract class messes with the form designer but
will still work

public void MakeRed()
{
this.BackColor = System.Drawing.Color.Red;
}

-to make the child forms

public class F2 : abForm
public class F3 : abForm

-in the mdi form
private void mdi_Load(object sender, System.EventArgs e)
{
F2 ff2 = new F2();
ff2.MdiParent = this;
ff2.Show();
F3 ff3 = new F3();
ff3.MdiParent = this;
ff3.Show();
}

private void button1_Click(object sender, System.EventArgs e)
{
foreach (Form f in this.MdiChildren)
{
((abForm) f).MakeRed();
}
}

The same principle would apply to events. If there is a way to make
the abstract form in a cleaner way (still allowing for the abstract
keyword without breaking the designer for the forms that inherit from
it), I hope one of the experts on this board will explain. The other
option would be to create an interface that specifies the MakeRed
method. The only reason to make the "abstract" form is that you don't
have to write the code inside MakeRed for every inherited form.
-Dan Shanyfelt
 
Back
Top