显示儿童表格时隐藏父表格的面板控制

时间:2013-08-16 05:09:01

标签: c# .net

当我打开另一个parent Form2的{​​{1}}按钮时,我试图隐藏对GroupSelect childform的Panel控件,当此GroupExmStart表单打开时,panel4应该隐藏,而当它关闭时它应该是可见的,我尝试了下面的代码,但它没有工作,也没有发生任何事情。我哪里出错了,我怎么能以正确的方式做到这一点?

父表单

child form GroupExmStart

儿童表格

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

2 个答案:

答案 0 :(得分: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 
}

答案 1 :(得分: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();
        }