sending message to parent form

  • Thread starter Thread starter Tarscher
  • Start date Start date
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
 
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.
 
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.
 
Back
Top