欢迎光临
我们一直在努力

终于搞定c#中对mdi的操作,代码见内(parent部分)-.NET教程,Windows开发

建站超值云服务器,限时71元/月

花了我一上午的时间,找来找去找不到答案,又是急性子,只好自己动手了,见笑,也请大家多提意见,谢了。

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();
        }
    }
}
 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 终于搞定c#中对mdi的操作,代码见内(parent部分)-.NET教程,Windows开发
分享到: 更多 (0)