【原创源码】(01):利用事件-委托,实现主-子窗体动态显示,不同菜单栏,不同工具栏。(类似SQL Server 2000 企业管理器)...

本教程详细介绍了如何使用C#和Windows窗体应用,通过事件和委托机制,实现类似SQLServer2000企业管理器的主子窗体界面设计。包括主窗体的创建、菜单栏和工具栏的配置,以及子窗体的动态加载和显示,确保不同子窗体间菜单栏和工具栏的切换。

【原创源码】(01):利用事件-委托,实现主-子窗体动态显示,不同菜单栏,不同工具栏。(类似SQL Server 2000 企业管理器)

欢迎大家发表意见(漏洞,性能等)。在博客园社区以外转载请注明作者和出处。谢谢

1,创建工程“EnterpriseManagerWindow”。

2,添加主界面“frmMain.cs”(Windows窗体)。

   在“frmMain.cs”中添加控件“menuStrip1”(MenuStrip)。

   设置“frmMain.cs”的属性:IsMdiContainer=True。

   设置“frmMain.cs”的属性:MainMenuStrip=menuStrip1。

   在“menuStrip1”中添加控件“fileToolStripMenuItem”(ToolStripMenuItem)
   在“menuStrip1”中添加控件“actionToolStripMenuItem”(ToolStripMenuItem)
   在“menuStrip1”中添加控件“viewToolStripMenuItem”(ToolStripMenuItem)
   在“menuStrip1”中添加控件“toolsToolStripMenuItem”(ToolStripMenuItem)
   在“menuStrip1”中添加控件“windowToolStripMenuItem”(ToolStripMenuItem)
   在“menuStrip1”中添加控件“helpToolStripMenuItem”(ToolStripMenuItem)

   在“windowToolStripMenuItem”中添加控件“consoleToolStripMenuItem”(ToolStripMenuItem)
   在“windowToolStripMenuItem”中添加控件“designToolStripMenuItem”(ToolStripMenuItem)

3,添加子界面“frmConsole.cs”(Windows窗体)。

   在“frmConsole.cs”中添加控件“toolStrip1”(ToolStrip)。

   在“toolStrip1”中添加控件“forwardToolStripButton”(ToolStripButton)
   在“toolStrip1”中添加控件“backToolStripButton”(ToolStripButton)

   在“frmConsole.cs”中添加委托,事件,触发方法,以及一个FormClosed事件代码。
     

None.gif     public   delegate   void  FormExitEventHandler();
None.gif        
public   event  FormExitEventHandler ExitEvent;
None.gif        
private   void  OnPost()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
if (this.ExitEvent != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif               
this.ExitEvent();
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
 
None.gif        
private   void  frmConsole_FormClosed( object  sender, FormClosedEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
this.OnPost();
ExpandedBlockEnd.gif        }

 

4,添加子界面“frmDesign.cs”(Windows窗体)。

   在“frmDesign.cs”中添加控件“toolStrip1”(ToolStrip)。

   在“toolStrip1”中添加控件“saveToolStripButton”(ToolStripButton)
   在“toolStrip1”中添加控件“attributeToolStripButton”(ToolStripButton)
   在“toolStrip1”中添加控件“setPrimaryKeyToolStripButton”(ToolStripButton)

   在“frmConsole.cs”中添加委托,事件,触发方法,以及一个FormClosed事件代码。
      

None.gif    public   delegate   void  FormExitEventHandler();
None.gif        
public   event  FormExitEventHandler ExitEvent;
None.gif        
private   void  OnPost()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
if (this.ExitEvent != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif               
this.ExitEvent();
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
 
None.gif        
private   void  frmDesign_FormClosed( object  sender, FormClosedEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
this.OnPost();
ExpandedBlockEnd.gif        }

None.gif


5,在主界面“frmMain.cs”中添加2个方法,2个事件。
       

None.gif   private   void  consoleToolStripMenuItem_Click( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            frmConsole obj 
= new frmConsole();
InBlock.gif            obj.ExitEvent 
+= new frmConsole.FormExitEventHandler(ConsoleExit);            
InBlock.gif            obj.MaximizeBox 
= true;
InBlock.gif            obj.MinimizeBox 
= true;
InBlock.gif            obj.ShowInTaskbar 
= false;
InBlock.gif            obj.StartPosition 
= FormStartPosition.Manual;
InBlock.gif            obj.WindowState 
= FormWindowState.Maximized;
InBlock.gif            obj.MdiParent 
= this;
InBlock.gif            obj.Show();
ExpandedBlockEnd.gif        }

None.gif
None.gif        
private   void  ConsoleExit()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
this.fileToolStripMenuItem.Visible = true;
InBlock.gif            
this.actionToolStripMenuItem.Visible = true;
InBlock.gif            
this.viewToolStripMenuItem.Visible = true;
InBlock.gif            
this.toolsToolStripMenuItem.Visible = true;
InBlock.gif            
this.windowToolStripMenuItem.Visible = true;
InBlock.gif            
this.helpToolStripMenuItem.Visible = true;
ExpandedBlockEnd.gif        }

None.gif
None.gif        
private   void  designToolStripMenuItem_Click( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
this.fileToolStripMenuItem.Visible = true;
InBlock.gif            
this.actionToolStripMenuItem.Visible = false;
InBlock.gif            
this.viewToolStripMenuItem.Visible = false;
InBlock.gif            
this.toolsToolStripMenuItem.Visible = false;
InBlock.gif            
this.windowToolStripMenuItem.Visible = true;
InBlock.gif            
this.helpToolStripMenuItem.Visible = true;
InBlock.gif
InBlock.gif            frmDesign obj 
= new frmDesign();
InBlock.gif            obj.ExitEvent 
+= new frmDesign.FormExitEventHandler(DesignExit);
InBlock.gif            obj.MaximizeBox 
= true;
InBlock.gif            obj.MinimizeBox 
= true;
InBlock.gif            obj.ShowInTaskbar 
= false;
InBlock.gif            obj.StartPosition 
= FormStartPosition.Manual;
InBlock.gif            obj.WindowState 
= FormWindowState.Maximized;
InBlock.gif            obj.MdiParent 
= this;
InBlock.gif            obj.Show();
ExpandedBlockEnd.gif        }

None.gif
None.gif        
private   void  DesignExit()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
this.fileToolStripMenuItem.Visible = true;
InBlock.gif            
this.actionToolStripMenuItem.Visible = true;
InBlock.gif            
this.viewToolStripMenuItem.Visible = true;
InBlock.gif            
this.toolsToolStripMenuItem.Visible = true;
InBlock.gif            
this.windowToolStripMenuItem.Visible = true;
InBlock.gif            
this.helpToolStripMenuItem.Visible = true;
ExpandedBlockEnd.gif        }

None.gif
None.gif


6, 附源代码:http://files.cnblogs.com/ClarkChan/EnterpriseManagerWindow_060920.rar


注意!在博客园社区以外转载,必须注明:
作者:Clark Chan
和原文出处:http://clarkchan.cnblogs.com/
否则谢绝转载!

转载于:https://www.cnblogs.com/ClarkChan/archive/2006/09/20/509902.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值