[英]Docking mdi controls in c#
我在左側的面板中有一個主要表單可點擊,具體取決於您單擊一種新類型的表單打開。 在righti有另一個面板,我想停靠點擊左側打開的表格。
如何在右側面板中將表單添加到另一個列表中? 下面的代碼的問題是它添加第一個元素罰款。 但是,當我添加第二個元素時,它們都會在面板后面消失:/
private void addToPanel2(Form o)
{
if (o is Form)
{
if (panel2.Controls.Count == 0)
{
o.MdiParent = this;
panel2.Controls.Add(o);
o.Dock = DockStyle.Top;
o.Show();
}
else
{
//then we know that this is an addable data item
foreach (Form obj in panel2.Controls)
{
if(obj.GetType().Name.Equals(o.GetType().Name))
{
//we dont want to add it as the data type is already open
MessageBox.Show("This data item must already be open. Please Check.");
}
else
{
// add it as its not in there
Form f = (Form)obj;
f.MdiParent = this;
f.Dock = DockStyle.Top;
f.Show();
}
}
}
}
謝謝
這是不可能的,MDI子表單不能是面板的子控件。 向面板添加非MDI表單也是一個不確定的主張,但是受到支持。 調用其SetTopLevel()方法,傳遞false,將其Visible屬性設置為true。 您還必須將其FormBorderStyle屬性設置為None,它不再作為頂級窗口正常運行。
這只是將它變成UserControl。 你最好把它變成一個UserControl,它使用更少的資源並且記錄得更好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.