2013-08-16 136 views
1

我試圖隱藏的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(); 
    } 
} 

回答

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

要創建新的窗口2,但我明白的問題侑父窗體是窗體2,所以你可以按照以下

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 
} 
+0

我想你的代碼,仍然是面板是可見的,此面板包含3 Picture Boxes – Durga

+0

你的孩子形式是由哪種形式創建的? – Damith

+0

GroupSelect(子窗體)由「Form2(父窗體)」創建,GroupExamStart(另一個子窗體)由GroupSelect(子窗體)創建。 – Durga