快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

一个多文档界面的应用程序

namespace Microsoft.Samples.WinForms.Cs.MDI {
using System;
using System.ComponentModel;
using System.Drawing;
using System.WinForms;

public class MainForm : System.WinForms.Form {
private System.ComponentModel.Container components;
private System.WinForms.MainMenu mainMenu;
private System.WinForms.StatusBar statusBar1;

private int windowCount = 0 ;

public MainForm() {

// Required by the Windows Forms Designer
InitializeComponent();

// TODO: Add any constructor code after InitializeComponent call

//Setup MDI stuff
this.IsMDIContainer = true;
this.MDIChildActivate += new EventHandler(this.MDIChildActivated);

//Add File Menu
MenuItem miFile = mainMenu.MenuItems.Add(\"&File\");
miFile.MergeOrder=0;
miFile.MergeType = MenuMerge.MergeItems;

MenuItem miAddDoc = new MenuItem(\"&Add Document\", new EventHandler(this.FileAdd_Clicked), Shortcut.CtrlA);
miAddDoc.MergeOrder=100;

MenuItem miExit = new MenuItem(\"E&xit\", new EventHandler(this.FileExit_Clicked), Shortcut.CtrlX);
miExit.MergeOrder=110;

miFile.MenuItems.Add(miAddDoc);
miFile.MenuItems.Add(\"-\"); // Gives us a seperator
miFile.MenuItems.Add(miExit);

//Add Window Menu
MenuItem miWindow = mainMenu.MenuItems.Add(\"&Window\");
miWindow.MergeOrder = 10;
miWindow.MenuItems.Add(\"&Cascade\", new EventHandler(this.WindowCascade_Clicked));
miWindow.MenuItems.Add(\"Tile &Horizontal\", new EventHandler(this.WindowTileH_Clicked));
miWindow.MenuItems.Add(\"Tile &Vertical\", new EventHandler(this.WindowTileV_Clicked));
miWindow.MDIList = true ; //Adds the MDI Window List to the bottom of the menu

AddDocument(); //Add an initial doc
}


//Add a document
private void AddDocument() {
windowCount++ ;
Document doc = new Document(\"Document \" + windowCount);
doc.MDIParent = this;
doc.Show();
}


//File->Add Menu item handler
protected void FileAdd_Clicked(object sender, System.EventArgs e) {
AddDocument() ;
}


//File->Exit Menu item handler
protected void FileExit_Clicked(object sender, System.EventArgs e) {
this.Close();
}


//One of the MDI Child windows has been activated
protected void MDIChildActivated(object sender, System.EventArgs e) {
if (null == this.ActiveMDIChild) {
statusBar1.Text = \"\";
} else {
statusBar1.Text = this.ActiveMDIChild.Text;
}
}

//Window->Cascade Menu item handler
protected void WindowCascade_Clicked(object sender, System.EventArgs e) {
this.LayoutMDI(MDILayout.Cascade);
}


//Window->Tile Horizontally Menu item handler
protected void WindowTileH_Clicked(object sender, System.EventArgs e) {
this.LayoutMDI(MDILayout.TileHorizontal);
}


//Window->Tile Vertically Menu item handler
protected void WindowTileV_Clicked(object sender, System.EventArgs e) {
this.LayoutMDI(MDILayout.TileVertical);
}


public override void Dispose() {
base.Dispose();
components.Dispose();
}

protected void InitializeComponent() {

this.components = new System.ComponentModel.Container();
this.mainMenu = new System.WinForms.MainMenu();
this.statusBar1 = new System.WinForms.StatusBar();

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.Text = \"MDI Example\";
this.Menu = mainMenu;
this.ClientSize = new System.Drawing.Size(450, 200);

statusBar1.BackColor = System.Drawing.SystemColors.Control;
statusBar1.Size = new System.Drawing.Size(496, 20);
statusBar1.TabIndex = 1;
statusBar1.Text = \"\";
statusBar1.Location = new System.Drawing.Point(0, 273);

this.Controls.Add(statusBar1);
}


public static void Main(string[] args) {
Application.Run(new MainForm());
}

}
}


作者:jspfuns


返回类别: 教程
上一教程: 利用 .NET 框架简化发布和解决 DLL Hell 问题
下一教程: 为您的应用程序加上注册的限制

您可以阅读与"一个多文档界面的应用程序"相关的教程:
· 转:创建多界面的应用程序 (好文章)
· 一个用c#写的扫描asp源码漏洞的应用程序(续)
· 一个用c#写的扫描asp源码漏洞的应用程序
· 为您的应用程序加上注册的限制
· 让用户通过宏和插件向您的 .NET 应用程序添加功能
    微笑服务 优质保证 索取样品