Newbie question: How to pass a click

T

T Waldren

How do you pass a click event from a MDI Parent to a Child form (in C#)?

For instance, I have a Parent MDI form that contains the code below. On the
click event that activates this code, I want it to add another tabpage to a
MDI Child form. I know I cannot jut make it ChildName.tabControlSearch.etc,
that gives you an error due to the level of protection (or is that what I
need to change?).



string title = "TabPage " + (tabControlSearch.TabCount + 1).ToString();

TabPage myTabPage = new TabPage(title);

tabControlSearch.TabPages.Add(myTabPage);



Thanks,

T. Waldren
 
T

T Waldren

Thanks,

Once I thought about it, that makes a lot of sense to do.

T. Waldren
Ian Cooper said:
Perhaps. WinForms makes your controls private by default (in C#) though
you can change this in the Design...Modifiers entry of the property grid. So
you could just alter this property so that the designer gives your control
an access modifier that lets your MDI parent access it. This may be what you
want, and it is a simple solution. However better is to encapsulate your MDI
child so that the parent does not know about its internal representation
(what happens, for example, if you later switch to a 3rd-party tab control;
you would probably need to change the calling code). In that case you might
want a method or property that allows you make this change, and hides the
implementation details from the caller. In your case, you might want a
method like this on the MDIChild:
public void CreateNewSearchTab(string tabTitle)
{
TabPage myTabPage = new TabPage(tabTitle);

tabControlSearch.TabPages.Add(myTabPage);
}
The advantage is that you have hidden away the implementation from the calling code.
If you have a number of children that all need to react to the same
instructions from the MDI Parent, but behave differently then consider
creating an interface with the required methods and implementing that
interface in your MDI child windows.
 
B

Bo Ching

You can cast the owner of your child form as parent form and access any
public or internal methods and properties.

for example
((ParentForm)this.Owner).myMethods();



hope this help

Bo
 

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

Top