[英]how to display form within another form when i click the menu item
i'm new to windows application.can anybody help me.here is my doubt.im having one parent form and it has four menu items.我是 windows 应用程序的新手。任何人都可以帮助我。这是我的疑问。我有一个父表单,它有四个菜单项。 when i click any of one menu item,it should display another form within that parent form itself.
当我单击任何一个菜单项时,它应该在该父表单本身中显示另一个表单。 how to do it?
怎么做?
Thanks in advance提前致谢
According to details you ve provided it seems that you need to use MDI Forms
concept in your app.根据您提供的详细信息,您似乎需要在您的应用程序中使用
MDI Forms
概念。 It s very easy to learn and refer to the following links:非常容易学习,参考以下链接:
http://www.codeproject.com/KB/cs/mdiformstutorial.aspx http://www.codeproject.com/KB/cs/mdiformstutorial.aspx
How to open a form within a form? 如何在表单中打开表单?
Just include the code in the 2nd link within your menuitem_Click event...只需在 menuitem_Click 事件的第二个链接中包含代码...
Hope this helps...希望这可以帮助...
There are several ways you could do it.有几种方法可以做到。
One simple way for a newcomer is to add the form to the parent form in the designer.对于新手来说,一种简单的方法是在设计器中将表单添加到父表单中。 Set the visible Property to false (in the properties) so it will not be shown at first when your program is run.
将 visible 属性设置为 false (在属性中),以便在程序运行时首先不会显示它。 Then you can set the visible property to true when you handle the menu item clicking.
然后,您可以在处理菜单项单击时将 visible 属性设置为 true。
There are code ways to do it too at runtime etc.在运行时等也有代码方法可以做到这一点。
Hers an article with stuff about adding controls (and implicitly child forms) at runtime.她有一篇关于在运行时添加控件(和隐式子窗体)的文章。
Inside your main form, add a panel and then use the below method to display the child form.在主窗体中,添加一个面板,然后使用以下方法显示子窗体。
private void InitChildForm(Form childForm, Panel parent)
{
childForm.TopLevel = false;
childForm.Parent = parent;
childForm.Dock = DockStyle.Fill;
childForm.Show();
parent.Parent = this;
parent.Dock = DockStyle.Fill;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.