C#自學之路32

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.