1.主要用到的控制項TreeView,Splitter,把父視窗IsMdiContainer設為True。子表單StartPosition=Manual,效果
用Splitter把父視窗分兩個部分,左邊放treeview,右邊顯示子表單。
開啟子視窗代碼
代碼
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
代碼
private void menu3_Click(object sender, EventArgs e)
{
//如果當前有子視窗開啟,關閉當前的視窗
if (this.MdiChildren.Length > 0)
{
this.ActiveMdiChild.Close();
}
DataBillSystem.ReWork.FrmReWork frmReWork = new DataBillSystem.ReWork.FrmReWork();
frmReWork.MdiParent = this;
frmReWork.Show();
}
檢查當前開啟的視窗
代碼
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) {
string nodeText = e.Node.Text;
bool isHaveWindow = false;
for (int i = 0; i < this.MdiChildren.Length; i++)
{
if (this.MdiChildren[i].Text.Equals(nodeText)) //查看有沒有相同的MDI子表單
{
this.MdiChildren[i].Activate(); //子表單已經被創立,啟用它
isHaveWindow = true;
break;
}
}//end for
}