本文介绍了在Winform应用程序中获取Active MDI Child表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在运行时创建mdichild表单.我正在保存mdichild表单的内容.只可以使用一种子形式.当出现多个子窗体时,我无法找到激活了哪个mdi子窗体.

我需要获取活跃的MDI子表格.

请注意:
Mainform.activemdichild返回null
我不知道为什么.

请帮我...


这是我的示例代码:Parent&下面给出的子表单代码示例...

Hi
I am creating mdichild form at run time. I am saving contents of mdichild form. It is OK for only one child form. When more than one child form occur, I could not find out which mdi child is activated.

I need to get the active mdi child form.

note that:
Mainform.activemdichild return null
I could not find out why.

Plz help me...


Here is my sample code: Both Parent & child form code sample given below...

public partial class Main:Form   {        
MDIChildForm childForm;
private ShowNewForm()
{
            childForm = new MDIChildForm();
            childForm.MdiParent = this;
            childForm.Display();
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case (Keys.Control|Keys.S):
                    childForm = (MDIChildForm)this.ActiveMdiChild;
                    SaveForm();
                    this.Focus();
                    return true;
                default:
                    return false;
            }
        }

private void SaveForm()
{
..........
..........
}
}


public partial class MDIChildForm: Form
{
public MDIChildForm()
{

}
public void Display()
{
            Width = 100;
            Height = 100;
            Left = 0;
            Top = 0;
            Text = "";
            Name = GenerateId();
            BackColor = Color.White;
            AutoScroll = true;
            MaximizeBox = false;
            
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Color.Blue, 2);
            g.Dispose();
            this.Focus();
}
}

推荐答案




这篇关于在Winform应用程序中获取Active MDI Child表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 12:56