制作自己的控制台[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 cocosoft 的 blog

       日前,有人问道:如何把一个子窗口设置为主窗口的“控制台”,也就是说,要在它上面进行一些系统性的操作。比如:功能的划分,子功能的调用。如果这样做出来的话,那么,它就具有操作直观性了。
       好了,废话不说了,进入正题吧:)

我们用一种方法:加一个子窗口,并设置该子窗口为最底层,在该子窗口上加一个可拉伸的图片框。当该子窗口被激活,就把它设置为最底层。并且,不允许用户关闭它,就可以了。
具体方法:
加载一个子窗口(form1),并重写该子窗口的onactivated事件:
protected override void onactivated(eventargs e)
{
sendtoback();
}
===================
在该子窗口上加上你要的picturebox
在主窗口中加载一个空窗口:form mdichile = null;
写主窗口的mdichildactiveate事件:
private void mainform_mdichildactivate(object sender, system.eventargs e)
{
form form = this.activemdichild;
if(form != null)
{
if(form is form1)
{
if(mdichile != null)
{
mdichile.activate();
}
}
else
{
mdichile = form;
}
}
else
{
form1.activate();
}
}
==================
这就可以了。:-)


下面是它的源代码:
源代码form1(主窗口):
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;

namespace demo
{
 /// <summary>
 /// form1 的摘要说明。
 /// </summary>
 public class form1 : system.windows.forms.form
 {
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private system.componentmodel.container components = null;
  private system.windows.forms.mainmenu mainmenu1;
  private system.windows.forms.menuitem menuitem1;
  private system.windows.forms.menuitem menuitem2;
  private form form = null;
  private form3 form3 = new form3();

  public form1()
  {
   //
   // windows 窗体设计器支持所必需的
   //
   initializecomponent();

   //
   // todo: 在 initializecomponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.dispose();
    }
   }
   base.dispose( disposing );
  }

  #region windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void initializecomponent()
  {
   this.mainmenu1 = new system.windows.forms.mainmenu();
   this.menuitem1 = new system.windows.forms.menuitem();
   this.menuitem2 = new system.windows.forms.menuitem();
   //
   // mainmenu1
   //
   this.mainmenu1.menuitems.addrange(new system.windows.forms.menuitem[] {
                       this.menuitem1});
   //
   // menuitem1
   //
   this.menuitem1.index = 0;
   this.menuitem1.menuitems.addrange(new system.windows.forms.menuitem[] {
                       this.menuitem2});
   this.menuitem1.text = "123";
   //
   // menuitem2
   //
   this.menuitem2.index = 0;
   this.menuitem2.text = "123";
   this.menuitem2.click += new system.eventhandler(this.menuitem2_click);
   //
   // form1
   //
   this.autoscalebasesize = new system.drawing.size(6, 14);
   this.clientsize = new system.drawing.size(508, 302);
   this.ismdicontainer = true;
   this.menu = this.mainmenu1;
   this.name = "form1";
   this.text = "form1";
   this.mdichildactivate += new system.eventhandler(this.form1_mdichildactivate);
   this.load += new system.eventhandler(this.form1_load);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>

本文关键:C# MDI 重绘代码
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top