Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / May 2007

Tip: Looking for answers? Try searching our database.

sending message to parent form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tarscher - 31 May 2007 10:48 GMT
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
Jeff Gaines - 31 May 2007 13:05 GMT
On 31/05/2007 in message

>Hi all,
>
[quoted text clipped - 4 lines]
>
>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.

Signature

Jeff Gaines

Tarscher - 31 May 2007 13:21 GMT
Thanks jeff, that worked perfectly.

Stijn

> On 31/05/2007 in message
>
[quoted text clipped - 34 lines]
> --
> Jeff Gaines

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.