none
如何让mdi 主窗体响应click事件 RRS feed

全部回复

  • click事件对应于响应mouse的click,

     Form2 form = new Form2();
     form.MdiParent = this.MdiParent; 
     form.Show();

    form2的click事件,可以通过定义一个委托方法于MdiParent类型中,form中的mouse click 直接调用

    MdiParent 的事件方法。

    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2018年5月25日 0:41
  • 你好,

    首先, 确认Form1 的 IsMdiContainer 设置为 true.

    然后初始化 Form1 和Form2, 设置Form1 作为 Form2's MdiParent:

    // Form1.IsMdiContainer should be true
    Form1 form1 = new Form1();
    
    // This automatically adds form2 into form1's MdiChildren collection
    Form2 form2 = new Form2();
    form2.MdiParent = form1;
    

    在 Form2 的代码,你可以参考一下下面的代码。

    public class Form2 : Form {
        // Include as data member so we only instantiate one Form3
        Form3 _form3;
    
        public Form2() {
            InitializeComponent();
            Button1.Click += new EventHandler(Button1_Click);
        }
    
        private void Button1_Click(object sender, EventArgs e) {
            if(_form3 == null) {
                _form3 = new Form3();
                // Set Form3's parent to be Form1
                _form3.MdiParent = this.MdiParent;
            }
        }
    }
    

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年5月25日 6:54
    版主