all groups > dotnet windows forms > may 2007 >
You're in the

dotnet windows forms

group:

sending message to parent form



sending message to parent form Tarscher
5/31/2007 2:48:21 AM
dotnet windows forms: 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
Re: sending message to parent form Jeff Gaines
5/31/2007 5:05:22 AM
On 31/05/2007 in message
[quoted text, click to view]

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.

--
Re: sending message to parent form Tarscher
5/31/2007 5:21:53 AM
Thanks jeff, that worked perfectly.

Stijn

[quoted text, click to view]

AddThis Social Bookmark Button