標籤:windows
32.基於單文檔和多文檔的應用程式
通常可以將Windows視窗應用程式分為3類:基於單一文件介面(SDI)應用程式,基於多重文件介面(MDI)應用程式和基於對話方塊的應用程式。
SDI應用程式中所有的視窗都是平等的,視窗之間不存在層次關係;MDI應用程式套件組合含一個父視窗(也稱為容器視窗)和一個或多個子視窗。對話方塊是Windows應用程式中重要的使用者介面元素之一,是使用者互動的重要手段。windows主要有3種對話方塊,模態對話方塊,非模態對話方塊,通用對話方塊。
基於多重文件介面(MDI)的應用程式。當父視窗關閉時,會自動關閉所有的子視窗,如果某個子表單關閉失敗,就會取消父視窗的關閉。多個子視窗只能有一個使用中視窗,它獲得使用者的輸入焦點,與使用者互動,進行前台資料處理。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
/*
Form2 form2 = new Form2();
form2.Show();
form2.MdiParent = this;
Form3 form3 = new Form3();
form3.Show();
form3.MdiParent = this;
Form4 form4 = new Form4();
form4.Show();
form4.MdiParent = this;
*/
}
private void 載入子表單ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
form2.MdiParent = this;
Form3 form3 = new Form3();
form3.Show();
form3.MdiParent = this;
Form4 form4 = new Form4();
form4.Show();
form4.MdiParent = this;
}
private void 水平平鋪ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi( MdiLayout.TileHorizontal );
}
private void 垂直平鋪ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi( MdiLayout.TileVertical );
}
private void 層疊平鋪ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi( MdiLayout.Cascade );
}
private void 關閉子表單ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form[] formList = this.MdiChildren;
foreach (Form form in formList)
{
form.Close();
}
}
}
}
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/6B/65/wKioL1Usvibj3m0YAAFYzL3ZOH0517.jpg" title=")YR%Z~``X{VR0PNUZT)$64V.png " alt="wKioL1Usvibj3m0YAAFYzL3ZOH0517.jpg" />
本文出自 “郭俊的部落格” 部落格,轉載請與作者聯絡!
C#自學之路32