1

我试图隐藏 Panel 控件parent Form2何时单击按钮GroupSelect childform打开另一个child form GroupExmStart,当此 GroupExmStart 表单打开而不是 panel4 应该隐藏并且当它关闭而不是它应该是可见时,我尝试了以下代码,但它不起作用并且什么都没有发生还。我在哪里错了,我该如何以正确的方式做到这一点?

父表格

public partial class Form2 : Form
{
    public Control control
    {
        //using this I accessed panel4 in child form GroupSelect
        get {return this.panel4; }
    }
}

子表

public partial class GroupSelect : Form
{
    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm2 = new Form2(lgnName);
        frm2.panel4.Visible = false;

        GroupExmStart grpexamfrm = new GroupExmStart(GrpID, DurationID, lgnName);
        grpexamfrm.MdiParent = this.ParentForm;
        //showing another child form and 
        grpexamfrm.Show();
    }
}
4

2 回答 2

0

您正在创建新的 form2,但据我了解,您的父表单的问题是 Form2,因此您可以执行以下操作

private void button1_Click(object sender, EventArgs e)
{ 
   var frm2  = this.Parent as Form2;
   if(frm2 !=null)
        frm2.control.Visible = false;

   GroupExmStart grpexamfrm = new GroupExmStart(GrpID, DurationID,lgnName);
   grpexamfrm.MdiParent = this.ParentForm;
   grpexamfrm.Show();//showing another child form and 
}
于 2013-08-16T05:14:36.213 回答
0

这段代码对我来说效果很好

在父表单中

public Form2(string userName)
        {
        InitializeComponent();            
        panelHide = panel4;
        }
public static Panel panelHide = new Panel();

在 GroupSelect 子窗体中

private void button1_Click(object sender, EventArgs e)
        {
            Form2.panelHide.Hide();
        }  
于 2013-08-16T14:12:57.783 回答