sending message to parent form

T

Tarscher

Hi all,

I have a usercontrol I place on different parent forms. When I double
click on something on the usercontrol I want to invoke a method on
those parent forms. I also need to pass an object from the user
control to the parent control when calling that method.

how can I do this best?

Thanks,
Stijn
 
J

Jeff Gaines

Hi all,

I have a usercontrol I place on different parent forms. When I double
click on something on the usercontrol I want to invoke a method on
those parent forms. I also need to pass an object from the user
control to the parent control when calling that method.

how can I do this best?

What about setting up an Event in your user control and subscribing to it
in your main form?

Something like (in the user control):

public delegate void ObjectSelected(object sender, object obtosend);
public event ObjectSelected OnObjectSelected;

private void FireObjectSelected(object obtosend)
{
if (OnObjectSelected != null)
{
OnObjectSelected(this, obtosend);
}
}

When you set up your user control in the main form (or in the load event)
subscribe to the event. When your control is double clicked call
FireObjectSelected.

You may want to change the name 'ObjectSelected', I have pasted this in
from one of my apps.
 
T

Tarscher

Thanks jeff, that worked perfectly.

Stijn

What about setting up an Event in your user control and subscribing to it
in your main form?

Something like (in the user control):

public delegate void ObjectSelected(object sender, object obtosend);
public event ObjectSelected OnObjectSelected;

private void FireObjectSelected(object obtosend)
{
if (OnObjectSelected != null)
{
OnObjectSelected(this, obtosend);
}

}

When you set up your user control in the main form (or in the load event)
subscribe to the event. When your control is double clicked call
FireObjectSelected.

You may want to change the name 'ObjectSelected', I have pasted this in
from one of my apps.
 

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