·首页 ·asp ·.net ·php ·JSP ·CGI ·数据库 ·网页设计 ·网管专栏 ·XML ·工具软件 ·办公软件 ·操作系统 ·程序设计 ·LINUX 
  当前位置: 普克>>计算机教程>>.net>>Windows开发>>终于搞定c#中对mdi的操作,代码见内
flash视频教学

photoshop专题

asp.net专题

office专题

终于搞定c#中对mdi的操作,代码见内(parent部分)


Windows开发 发表时间:2006-4-8 字体:  返回
花了我一上午的时间,找来找去找不到答案,又是急性子,只好自己动手了,见笑,也请大家多提意见,谢了。

parent.cs
------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace testagain
{
    /// <summary>
    /// Summary description for parent.
    /// </summary>
    public class parent : System.Windows.Forms.Form
    {
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem m_FileMenu;
        private System.Windows.Forms.MenuItem m_OpenFile;
        private System.Windows.Forms.MenuItem m_Close;
        private System.Windows.Forms.MdiClient mdiClient1;
        private System.Windows.Forms.MenuItem menuItem1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public parent()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            testform f_test = new testform(this);
            f_test.Show();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        public static void Main()
        {
            Application.Run(new parent());
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.m_FileMenu = new System.Windows.Forms.MenuItem();
            this.m_OpenFile = new System.Windows.Forms.MenuItem();
            this.m_Close = new System.Windows.Forms.MenuItem();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.mdiClient1 = new System.Windows.Forms.MdiClient();
            this.SuspendLayout();
            //
            // mainMenu1
            //
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.m_FileMenu,
                                                                                      this.menuItem1});
            //
            // m_FileMenu
            //
            this.m_FileMenu.Index = 0;
            this.m_FileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                       this.m_OpenFile,
                                                                                       this.m_Close});
            this.m_FileMenu.Text = "文件(&F)";
            //
            // m_OpenFile
            //
            this.m_OpenFile.Index = 0;
            this.m_OpenFile.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
            this.m_OpenFile.Text = "Dns探测";
            this.m_OpenFile.Click += new System.EventHandler(this.m_OpenFile_Click);
            //
            // m_Close
            //
            this.m_Close.Index = 1;
            this.m_Close.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
            this.m_Close.Text = "关闭";
            this.m_Close.Click += new System.EventHandler(this.m_Close_Click);
            //
            // menuItem1
            //
            this.menuItem1.Index = 1;
            this.menuItem1.Text = "关于...(&A)";
            this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
            //
            // mdiClient1
            //
            this.mdiClient1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mdiClient1.Name = "mdiClient1";
            this.mdiClient1.TabIndex = 0;
            //
            // parent
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(536, 309);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.mdiClient1});
            this.IsMdiContainer = true;
            this.Menu = this.mainMenu1;
            this.Name = "parent";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "MDI窗体操作演示_父窗体";
            this.ResumeLayout(false);

        }
        #endregion

        private void menuItem1_Click(object sender, System.EventArgs e)
        {
            Form f_activeform = this.ActiveMdiChild;
            if (f_activeform != null)
            {
                if (f_activeform.Name != null && f_activeform.Name != "parent")
                {
                    f_activeform.Close();
                }
            }
            child child_form = new child(this);        
            
            child_form.Show();
            
        }

        private void m_Close_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void m_OpenFile_Click(object sender, System.EventArgs e)
        {
            Form f_activeform = this.ActiveMdiChild;
            
            if (f_activeform != null)
            {
                if (f_activeform.Name != null && f_activeform.Name != "parent")
                {
                    f_activeform.Close();
                }
            }
            testform f_test = new testform(this);
            f_test.Show();
        }
    }
}
 


上一篇:老外编的程序(六)--目录操作
下一篇:c#中对mdi的操作,代码见内(child部分)

普克创业投资网刊载此文不代表同意其说法或描述,仅为提供更多信息。
在百度中搜索终于搞定c#中对mdi的操作,代码见内(parent部分)的相关内容]   [在狗狗中搜索终于搞定c#中对mdi的操作,代码见内(parent部分)的相关内容]
Copyright @ 2006 PUPK.COM 普克创业投资网 版权所有
 建议使用1024*768以达到最好的浏览效果