创建选项卡式 MDI 界面
我正在使用 C# 2005 开发 Windows 应用程序。 我计划使用选项卡容器来显示子表单。 我使用了菜单条来显示菜单,并设置了 MainMenu 窗体的 IsMDIContainer = true 属性。 MainMenu 窗体还包含一个选项卡控件,我计划将所有子窗体显示为选项卡控件中的点击页面。
到目前为止,我已经能够在用户选择菜单选项时添加选项卡页。 但我不知道如何在选项卡页中显示子表单本身。
我在菜单单击事件中使用了以下代码。
frmPurchaseEntry PurchaseEntry = new frmPurchaseEntry;
PurchaseEntry.MdiParent = this;
PurchaseEntry.TabCtrl = tabControl1;
TabPage tpPurchaseEntry = new TabPage();
tpPurchaseEntry.Parent = tabControl1;
tpPurchaseEntry.Text = "Purchase Entry";
tpPurchaseEntry.Show();
PurchaseEntry.TabPag = tpPurchaseEntry;
PurchaseEntry.Show();
tabControl1.SelectedTab = tpPurchaseEntry;
如何在标签页中正确显示子表单? 我不需要文件 -> 新型应用程序,其中菜单单击事件显示相同的(空白)表单。 我的菜单选项应该每个都显示独特/独特的形式。
谢谢。
拉利特·库马尔·巴里克
I am using C# 2005 to develop an Windows application. I am planning to use a Tab Container to display the child forms. I have used a Menu Strip to display the menu and have set IsMDIContainer = true property of the MainMenu form. The MainMenu form also contains a Tab Control and I plan to display all child forms as Tap Pages in the Tab Control.
Till now I have been able to add Tab Pages when the user chooses a menu option. But I don't know how to display the child form itself within the Tab Page.
I have used the following code in the menu click event.
frmPurchaseEntry PurchaseEntry = new frmPurchaseEntry;
PurchaseEntry.MdiParent = this;
PurchaseEntry.TabCtrl = tabControl1;
TabPage tpPurchaseEntry = new TabPage();
tpPurchaseEntry.Parent = tabControl1;
tpPurchaseEntry.Text = "Purchase Entry";
tpPurchaseEntry.Show();
PurchaseEntry.TabPag = tpPurchaseEntry;
PurchaseEntry.Show();
tabControl1.SelectedTab = tpPurchaseEntry;
How can I display the child form properly in the Tab Page?? I don't want a File -> New type of application, where menu click event displays the same (blank) form. My menu options should each display a unique/distinct form.
Thank You.
Lalit Kumar Barik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
子窗体的 Parent 属性可能会有所帮助。 将其设置为 tabpage 对象,看看会发生什么。
编辑:显然,这会引发 ArgumentException。 “顶级控件无法添加到控件中。” 您可以将表单的内容放入面板或其他内容中,然后设置该面板的 Parent 属性。
我自己使用的另一个选项是使用一个假 TabStrip,它调用相关表单上的Activate() 方法。 它通过枚举父级的 MdiChildren 列表来绘制选项卡,并记住每个选项卡的 hitrect。
The Parent property of the child form could help. Set that to the tabpage object and see what happens.
Edit: Apparently, this raises an ArgumentException. "Top-level control cannot be added to a control." You could instead put the form's content in a Panel or something, then set that Panel's Parent property.
The other option, which I use myself, is to have a fake TabStrip which calls the Activate() method on the relevant forms. It draws the tabs by enumerating the parent's MdiChildren list, remembering the hitrects for each.