[Original source code] (01): Uses event-delegate to dynamically display the main and sub-forms, with different menus and toolbar. (Similar to SQL Server 2000 Enterprise Manager)
Comments (vulnerabilities, performance, etc.) are welcome ). In blogCommunityOtherwise, please indicate the author and source. Thank you!
1. Create the project "enterprisemanagerwindow ".
2. Add the main interface "frmmain. cs" (Windows form ).
Add the control "menustrip1" (menustrip) in "frmmain. cs ).
Set "frmmain. cs" attribute: ismdicontainer = true.
Set the attribute of "frmmain. cs": mainmenustrip = menustrip1.
Add the control "filetoolstripmenuitem" in "menustrip1" (toolstripmenuitem)
Add the control "actiontoolstripmenuitem" (toolstripmenuitem) in "menustrip1)
Add the control "viewtoolstripmenuitem" in "menustrip1" (toolstripmenuitem)
Add the control "toolstoolstripmenuitem" in "menustrip1" (toolstripmenuitem)
Add the control "windowtoolstripmenuitem" in "menustrip1" (toolstripmenuitem)
Add the control "helptoolstripmenuitem" (toolstripmenuitem) in "menustrip1)
Add the consoletoolstripmenuitem control to "windowtoolstripmenuitem" (toolstripmenuitem)
Add the designtoolstripmenuitem control to "windowtoolstripmenuitem" (toolstripmenuitem)
3. Add the sub-interface "frmconsole. cs" (Windows form ).
Add the control "toolstrip1" (toolstrip) in "frmconsole. cs ).
Add the control "forwardtoolstripbutton" (toolstripbutton) in "toolstrip1)
Add the control "backtoolstripbutton" (toolstripbutton) in "toolstrip1)
Add a delegate, event, trigger method, and a formclosed event to "frmconsole. cs ".Code.
Public Delegate Void Formexiteventhandler ();
Public Event Formexiteventhandler exitevent;
Private Void Onpost ()
{
If ( This . Exitevent ! = Null )
{
This. Exitevent ();
}
}
Private Void Frmconsole_formclosed ( Object Sender, formclosedeventargs E)
{
This. Onpost ();
}
4. Add the sub-interface "frmdesign. cs" (Windows form ).
Add the control "toolstrip1" (toolstrip) in "frmdesign. cs ).
Add the control "saverelstripbutton" (toolstripbutton) in "toolstrip1)
Add the butetoolstripbutton (toolstripbutton) control to "toolstrip1)
Add the control "setprimarykeytoolstripbutton" (toolstripbutton) in "toolstrip1)
Add the delegate, event, trigger method, and formclosed Event code in "frmconsole. cs.
Public Delegate Void Formexiteventhandler ();
Public Event Formexiteventhandler exitevent;
Private Void Onpost ()
{
If ( This . Exitevent ! = Null )
{
This. Exitevent ();
}
}
Private Void Frmdesign_formclosed ( Object Sender, formclosedeventargs E)
{
This. Onpost ();
}
5. Add two methods and two events to the main interface "frmmain. cs.
Private Void Leletoolstripmenuitem_click ( Object Sender, eventargs E)
{
Frmconsole OBJ = New Frmconsole ();
OBJ. exitevent + = New Frmconsole. formiteventhandler (consoleexit );
OBJ. maximizebox = True ;
OBJ. minimizebox = True ;
OBJ. showintaskbar = False ;
OBJ. startposition = Formstartposition. Manual;
OBJ. windowstate = Formwindowstate. maximized;
OBJ. mdiparent = This ;
OBJ. Show ();
}
Private Void Consoleexit ()
{
This . Filetoolstripmenuitem. Visible = True ;
This . Actiontoolstripmenuitem. Visible = True ;
This . Viewtoolstripmenuitem. Visible = True ;
This . Toolstoolstripmenuitem. Visible = True ;
This . Windowtoolstripmenuitem. Visible = True ;
This . Helptoolstripmenuitem. Visible = True ;
}
Private Void Designtoolstripmenuitem_click ( Object Sender, eventargs E)
{
This . Filetoolstripmenuitem. Visible = True ;
This . Actiontoolstripmenuitem. Visible = False ;
This . Viewtoolstripmenuitem. Visible = False ;
This . Toolstoolstripmenuitem. Visible = False ;
This . Windowtoolstripmenuitem. Visible = True ;
This . Helptoolstripmenuitem. Visible = True ;
Frmdesign OBJ = New Frmdesign ();
OBJ. exitevent + = New Frmdesign. formiteventhandler (designexit );
OBJ. maximizebox = True ;
OBJ. minimizebox = True ;
OBJ. showintaskbar = False ;
OBJ. startposition = Formstartposition. Manual;
OBJ. windowstate = Formwindowstate. maximized;
OBJ. mdiparent = This ;
OBJ. Show ();
}
Private Void Designexit ()
{
This . Filetoolstripmenuitem. Visible = True ;
This . Actiontoolstripmenuitem. Visible = True ;
This . Viewtoolstripmenuitem. Visible = True ;
This . Toolstoolstripmenuitem. Visible = True ;
This . Windowtoolstripmenuitem. Visible = True ;
This . Helptoolstripmenuitem. Visible = True ;
}
6. AttachmentSource code: Http://files.cnblogs.com/ClarkChan/EnterpriseManagerWindow_060920.rar
Note! Reposted outside the blog community, which must be noted:
By Clark Chan
And Source: http://clarkchan.cnblogs.com/
Otherwise, reprint is declined!