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 / August 2005

Tip: Looking for answers? Try searching our database.

Contained Forms + Events + Best Method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
snesbit - 25 Aug 2005 12:55 GMT
Environment:

                       The main SDI Window form has a toolbar component
docked at the top, a panel in the middle and a status bar component at the
bottom.

                      All forms are separate files and are placed in the
panel on the main SDI Window at runtime.

Issue:

                      The toolbar throws events which the forms being
displayed at runtime inside the panel on the main SDI Window need to
capture.

What's the best method of implementation? I'm  Looking for a nice clean
solution.
"Jeffrey Tan[MSFT]" - 26 Aug 2005 07:14 GMT
Hi snesbit,

Thanks for your post.

Based on my understanding, the Toolbar on your main Form applicaiton may
fire certain event, and all the forms contained inside the main Form's
panel should react to this event.

I think for all the child forms, we can add an extra parameterized
constructor to it. Then when dynamically creating the child form in main
form's code, we can explicitly pass the main Form reference through the
parameter to the child form, in the child form, it can register the main
Form toolbar event in the parameterized constructor.

Then, whenever the toolbar event is fired, all the registered child forms
will react to this event without any problem. If I misunderstand you,
please feel free to tell me, thanks

Hope this helps.
===========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Steve Nesbit - 26 Aug 2005 13:05 GMT
It sounds like an interesting approach.  How can you register the mainform
toolbar events in the child?

> Hi snesbit,
>
[quoted text clipped - 25 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 29 Aug 2005 02:26 GMT
Hi Steve,

Thanks for your feedback.

Yes, if our ToolBar reference is private, we can not register the event
handler directly. For this, I have 2 options:
1. Create a public method in Base form. This method takes 1 parameter as
type [YourToolBarSpecific]EventHandler and registers Toolbar event in this
method, then in child Form, we can invoke this method with a valid
eventhandler. Sample code like this:
//In main form
public void ButtonAddHandler(EventHandler eh)
{
    this.button1.Click+=eh;
}

private void button2_Click(object sender, System.EventArgs e)
{
    Form2 f=new Form2(this);
}
//In child form
public Form2(Form1 f)
{
    f.ButtonAddHandler(new EventHandler(f_Click));
    InitializeComponent();
}
private void f_Click(object sender, EventArgs e)
{
    MessageBox.Show("hehe");
}

2. Just modifiy the ToolBar modifier as public

Hope this helps
=====================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Jeffrey Tan[MSFT]" - 31 Aug 2005 08:02 GMT
Hi Steve,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Rate this thread:







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.