2012-12-20 18 views
0

我希望這是一件容易的事,但我需要一些幫助。如何在移除後將面板正確放入表單中?

SomeForm f = new SomeForm(); 

    if (someStatement) // relocate pnlRight onto new form f 
     { 
      this.Controls.Remove(pnlRight); 
      f.Controls.Add(pnlRight); 

      pnlRight.Location = new Point(0, 0); // I want to place pnlRight at (0, 0) on the new form f 
      this.pnlRight.Visible = false; 
      f.Show(); 
     } 
    else // hide form and relocate pnlRight onto main form 
     { 
      this.pnlRight.Location = new Point(pnlLeft.Location.X + pnlLeft.Width + 10, pnlLeft.Location.Y); 
      this.Controls.Add(pnlRight); 
      this.pnlRight.Visible = true; 

      frmSettings.Hide(); 
     } 

所以 - 我有一個主窗體有兩個面板:pnlLeft和pnlRight。在按鈕點擊(這裏如果someStatement是真的)pnlRight應該重新定位在一個新創建的表單上。完美的作品。但是:如果我再次將pnlRight重新定位到主窗體上,它不會放置在我想要的位置,而是位於pnlLeft上方的(0,0)處。怎麼了?我檢查了兩個面板的屬性,並且看不到任何可能性。也許有人有一個提示對我來說,

最佳 丹尼斯

+0

如果someStatement = false,則您在此處顯示的代碼將爲控件集合添加一個額外的pnlRight引用。這是實際的代碼還是隻是一個修改例子? – K3N

回答

0

如果你在你的表格2塊板,那麼你需要設置你想顯示他們兩個序列中的面板的Dock屬性。

相關問題