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 / September 2004

Tip: Looking for answers? Try searching our database.

Reusing a Form's Toolbar and Menu

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Terry McGinty - 15 Sep 2004 18:32 GMT
I created a form with a toolbar and main menu.  The form is basically
a text editor similar to WordPad.  Now I have a second form that I
determined would benefit from having the toolbar and menu items (and
associated code) from the first form.  The second form has additional
toolbars of its own and has a different editing area.

My question is: What is the best way to reuse toolbar and main menu
items (and associated code) in multiple forms?

I've thought of three approaches, but am not sure which one would be
the best approach:

1. Create a base form and then host that form within another form.  In
this approach I would create a form with the toolbar, main menu, and
all associated code.  I could then host this base form inside other
forms, by treating it as a control.  I actually did do this with some
code that looks like this:

    _editorForm = new EditorForm();
    _editorForm.TopLevel = false;
    _editorForm.Dock = DockStyle.Fill;
    _editorForm.FormBorderStyle = FormBorderStyle.None;
    _panelClientArea.Controls.Add(_editorForm); // This is a panel which
    //fills up the client area of the host form
    _editorForm.Show();
    _editorForm.BringToFront();

2. Create a base UserControl and then host that control within another
form.  This is the same approach as above, but instead of using a
Form, I would put the Toolbar and Menu code in a UserControl.  (You
cannot put a MainMenu control on a UserControl, but you could generate
the MainMenu in code and then return it from a method of the
UserControl class).

3. Create a base form and then inherit from that form (visual
inheritance).

Or is there a better approach?

My goal is simply to avoid code duplication and to allow for reuse of
toolbars and main menus (and associated code).  Any suggestions or
references would be appreciated.

Thanks.

Terry McGinty
Sijin Joseph - 16 Sep 2004 12:40 GMT
1 does not seem like a good solution, with 2 i am not sure since there
is a MainMenu involved. I would say go with Visual inheritance.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I created a form with a toolbar and main menu.  The form is basically
> a text editor similar to WordPad.  Now I have a second form that I
[quoted text clipped - 42 lines]
>
> Terry McGinty

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.