2011-02-06 83 views
0

即時通訊使用visual c#2008,我試圖從usercontrol1打開usercontrol2。使用事件處理,但仍然無法加載usercontrol1,但能夠關閉usercontrol1。如何點擊usercontrol打開anoter usercontrol?

請幫助我..

+0

發佈你的試用代碼,它可能有助於解決問題 – Binil 2011-02-06 05:00:21

+0

你應該打開新的*形式*,而不是usercontrols。你可以將它們粘貼在一個像按鈕或任何其他控件的窗體上。這聽起來像你的設計嚴重破碎。 – 2011-02-06 05:11:16

回答

1

試試這個

void UserControl1_Click(object sender, EventArgs e) 
    { 
     UserControl2 u2 = new UserControl2(); 
     this.Parent.Controls.Add(u2); // if you want to add to parent 
     //this.Controls.Add(u2); // if you want to add to the first UserControl 
     u2.BringToFront(); 
     this.Visible = false; 
     u2.Visible = true; 
    } 

我覺得你的問題是,你沒有指派usercontrol2 到家長控制集合。