MDI和在TabPage

无奈的.net探索


MDI和在TabPage中增加Form分页?

MDI(Multiple Document Interface)是一种在窗口中嵌套窗口的接口, 与之对应的是SDI(Single Document Interface).

需要注意的是:
1 在FatherForm中将属性IsMDIContainer设置为True.
2 FatherForm中增加一个MenuStrip, 其中增加一个button. 其中的click事件中, 增加代码为

public void button_click(Sender object, ClickArges e)
{
	ChildForm c1 = new ChildForm();
	c1.MdiParent = this;
    c1.Show();

	ChildForm c2 = new ChildForm();
	c2.MdiParent = this;
    c2.Show();

	// 窗口的排列方式
	LayoutMdi.layout(MdiLayout.TileHorizon);
}

类似的, 如果想将一个Form作为一个页面放入一个TabControl或者类似的PageContainer中. 需要做的是

Form page_form = new PageForm();
page_form.TopLevel = false;
page.Controls.Add(page_form);
page_form.Show();

一般地是把Form当作是TopLevel的控件的, 但是依然可以将其作为一个普通的控件来用, 否则会报错, 不能将顶级元素应用在Container中.

原文地址:https://www.cnblogs.com/putuotingchan/p/8628763.html