简体   繁体   English

单击菜单项时如何在另一个表单中显示表单

[英]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.

相关问题 当我双击特定项目时,如何将form2列表框中的选定项转移到form1中的文本框 - how to transfer selected item in listbox in form2 to textbox in form1 when i double click on particular item 如何在打开另一个表单的同时单击第一个表单上的项目 - How to click item on first form while having another form open 单击按钮时,将打开一个新表单。 当我点击另一个表单时,如何将此表单保留在前台? - When I click a button, a new form opens. How do I keep this form in the foreground when I click on another form? 如何从另一个表单按钮更改表单菜单项的文本 - How do i change text of form menu item from another forms button 如何访问另一个类中的部分类中的表单项? - How to access form item in partial Class within another Class? 窗体运行时,不显示上下文菜单项 - Context Menu Item is not showing when form is running 如何点击父表格时关闭子表格? - How Can i Close Child Form when Click on Parent Form? 单击按钮时如何打开另一个表单? - How do I make another form open when I click a button? 当我单击按钮转到Winforms中的另一个表单时,应用程序冻结 - Application freezes when I click on button to go to another form in winforms 如何响应菜单项的单击显示模式形式? - How can I display a modal form in response to a click on a MenuItem?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM