时间:2019-05-27 标签:c#winForms在mainform中打开窗体

发布于 2024-10-09 22:03:47 字数 495 浏览 0 评论 0原文

我已经编写了 C# 应用程序,我将发布屏幕截图。在这个主窗体中有 3 个按钮,可打开不同的窗体。现在我决定修改这个应用程序,我想制作一个带有条形菜单的主窗体,它将打开该窗体。我使用了这段代码,但我不喜欢或者我做错了什么。我不喜欢,因为父级中有子控件(最小化、最大化、关闭)(请参阅第二张图片):

请给我一些建议。 MDI 适合这样的工作吗?谢谢!

Sell sell = new Sell();
sell.MdiParent = this;
sell.Dock = DockStyle.Fill;
sell.Show();`

alt text

所以我的问题是,当我打开子表单时,父表单未填写,这是屏幕,如何使其成为父表单表单已填充子表单 alt text

I have programmed c# application i will post screenshot. In this main form is 3 buttons which opens different forms. Now i decided to modify this application I want to Make one main form with strip menu which will open this forms. I used this code but i don't like or i'm doing something wrong. I don't like because there is child controls(minimize, maximize, close) in parent (please see second picture ):

alt text

Please advice me something. Is MDI good for such job? Thanks!

Sell sell = new Sell();
sell.MdiParent = this;
sell.Dock = DockStyle.Fill;
sell.Show();`

alt text

So my problem is that parent form is not filling when i open child form this is creen how to make that it parent form was filled with child form alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

已下线请稍等 2024-10-16 22:03:47

看到您的最新编辑,我认为您的子表单内容即使最大化也不会填满屏幕的原因是您的内容/布局不灵活。

无论您在设计模式期间将控件放置在何处,它们在运行时都会最终放置在何处,无论您将窗口设置为多大或多小。如果窗口太小而无法容纳所有这些内容,它们要么会被覆盖,要么您会看到滚动条。或者,如果窗口做得比需要的大,您会看到很多空白空间。

解决此问题的方法是设置 Dock控件的 Anchor 属性,这会导致它们扩展和压缩以适应其包含表单的布局。您还可以将控件放置在 TableLayoutPanel< /code>FlowLayoutPanel< /code>控件来帮助管理其布局。

至于您最初提出的问题,我仍然无法判断您是否反对 MDI 应用程序的外观,或者您是否只是不明白如何正确实现它。您提供的澄清评论实际上让事情对我来说变得不太清楚 - 您发布了一个代码片段,但没有解释它的含义。正如我在评论中所写,没有(非黑客)方法来显示没有最小化、最大化和关闭按钮的表单(将 FormBorderStyle 属性设置为“None”可以做到这一点,但我认为这是一个愚蠢的解决方案,它只会让您使用错误的控件来完成工作 - 它不会像表单一样运行,用户将无法像表单一样移动它,等等。那么为什么< em>使用表单?)。

如果您确实希望拥有一个中心内容不断变化的应用程序窗口,则应该创建一系列 用户控件。您可以使用必要的子控件来布局每个用户控件,就像使用表单一样(使用我上面讨论的流体布局技术),将每个用户控件添加到主窗体中,设置每个控件的 Dock 属性设置为“填充”(以便它们填充整个查看区域),然后编写代码以简单地交换主窗体查看区域中当前可见的用户控件。与 Panel 之类的东西相比,使用 UserControl 的优点是您可以将所有代码合并到一个控件中,就像使用 Form 一样。代码>.您可以使用选项卡控件,但如果您不想显示任何有关存在多个表单的指示(这就是您的目标),那么这也将是该作业的错误控件。

如果您确实想在主窗体中打开子窗体(如您的问题标题所示),那么您确实应该使用 MDI。如果您不明白如何执行此操作,则需要进一步澄清您的问题。

Seeing your latest edit, I assume the reason that your child form's content doesn't fill the screen even when it's maximized is because your content/layout is not flexible.

Wherever you've placed the controls during Design Mode is where they're going to end up at run time, regardless of how big or small you make the window. If the window is too small to contain all of them, they'll either be covered up or you will see scrollbars. Alternatively, if the window is made larger than necessary, you'll see a lot of empty space.

The way around this is either to set the Dock and Anchor properties of your controls, which causes them to expand and compress to fit the layout of their containing form. You could also place your controls inside a TableLayoutPanel or FlowLayoutPanel control to help manage their layout.

As far as the question you appeared to be asking originally, I still can't tell if you're opposed to the way an MDI application looks, or if you simply don't understand how to correctly implement it. The clarification comment you offered actually makes things less clear to me—you posted a code snippet, but didn't explain what it means. As I wrote in a comment, there's no (non-hackish) way to show a form that doesn't have minimize, maximize, and close buttons (setting the FormBorderStyle property to "None" does this, but I think this is a silly solution that simply allows you to use the wrong control for the job—it won't behave like a form, the user won't be able to move it around like a form, etc. so why use a form?).

If you truly want to have a single application window with changing content in the center, you should create a series of UserControls. You can lay out each user control with the necessary child controls, just like you would with a form (using the fluid layout techniques I discussed above), add each user control to your main form, set each control's Dock property to "Fill" (so that they fill the entire viewing area), and then write code to simply swap out the currently visible user control in your main form's viewing area. The advantage of using a UserControl versus something like a Panel is that you consolidate all of your code into a single control, much like you would with a Form. You could use a tab control, but if you don't want to show any indication that there are multiple forms (which is what your aim appears to be), this would also be the wrong control for the job.

If you literally want to open child forms inside your main form, as your question title indicates, you should indeed be using MDI. If you don't understand how to do this, you'll need to clarify your question further.

不一样的天空 2024-10-16 22:03:47

将父窗体的 MDI Container 属性设置为 true。会有帮助的。

Set MDI Container property to true for your parent form. It will help.

我的鱼塘能养鲲 2024-10-16 22:03:47

设置表格

FormBorderStyle = None

为您的孩子

Set

FormBorderStyle = None

for your child forms

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文