如何在同一窗口中打开新表单 [英] How do I open new form in the same window

查看:84
本文介绍了如何在同一窗口中打开新表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中创建一个应用程序,它有一个菜单,其中包含与之链接的表单,我希望当我们点击任何菜单链接时,应该有一个父表单,有一个面板或窗口,它的.cs表单应该在窗口中加载,因此我们可以单击其他窗口,它们的表单应该替换当前窗体。

所以我需要在Form1(f1)中打开Form2(f2)



我尝试了什么:



I am making an application in C#, and it has a menu, having forms linked with it, i want that there should be a parent form, having a panel or window, when we click on any menu link, its .cs form should be loaded in the window, and so we can click on other windows, and their forms should replace the current one.
So I need Form2 (f2) to open within Form1 (f1)

What I have tried:

Form1 f1= new Form1();
Form2 f2= new Form2();
f1.IsMdiContainer= true;
f2.MdiParent= f1;
f2.Show();

推荐答案

如果是我,我会创建一个SDI应用程序,实现所有的可切换的表单作为用户控件,并将它们放在主窗口上。此时,我将使用菜单显示/隐藏相应的表单。
If it were me, I would create a SDI application, implement all of the switchable forms as user controls, and place them on the main window. At that point, I would use the menu to show/hide the appropriate forms.


这篇关于如何在同一窗口中打开新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆