容器形式的控件优于子形式?
在容器表单中,我有菜单和按钮来打开这些表单。
这里,当我打开任何表单时,这些按钮和标签来自新打开的表单,我遇到一个问题。
请指导我如何解决此问题?我想打开一个新表单并将这些容器表单的控件保留在其后台。
In a container form I have menu and buttons to open ther forms.
Here I am facing a problem when I open any form these buttns and lables come over newly opened form.
Please guide me how I can manage this issue? I want to open a new form and keep these container form's controls in back ground of it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我想我明白你做了什么。您正在使用 MDI,并将菜单标签和按钮放在 MDI 父窗体上。您对 MDI 客户端窗口做了一些操作,它通常是深灰色的。也许您已经知道如何更改其 BackColor 或更改 Windows 系统颜色。
是的,你的截图就是预期的结果。问题在于 MDI 客户端窗体是 MDI 客户端窗口的父级。这使得它们显示在您放置在父窗体上的控件后面。
没有解决方法,您将不得不更改您的用户界面。要保留 MDI,请将 Panel 放在父窗体上并将其 Dock 属性设置为 Left。将菜单控件移至其上。 MDI 客户端窗口现在将缩小,占据父窗体的剩余部分。子窗体会将自己限制在该区域。令人痛苦的一点是,您必须重新组织菜单以适应面板中更小的可用空间。
I think I see what you did. You are using MDI and you put the menu labels and buttons on the MDI parent form. You did something with the MDI client window, it is normally dark-gray. Maybe you figured out how to change its BackColor or changed the Windows system color.
Yes, your screenshot is then the expected result. The problem is that MDI client forms are parented to the MDI client window. Which makes them show up behind the controls you put on the parent form.
There is no workaround for this, you are going to have to change your UI. To keep MDI, put a Panel on the parent form and set its Dock property to Left. Move the menu controls on that. The MDI client window will now shrink, occupying the remainder of the parent form. And the child forms will constrain themselves to that area. The wee painful bit is that you'll have to reorganize the menu to fit the much smaller space available in the panel.
我也有同样的问题。我得到了如下所述的替代解决方案:
并执行了以下操作
I've also got the same problem. I got an alternative solution as described below:
And did the following
如果它是 MDI 应用程序并且您将控件放在父窗口中,那么它们将显示在任何创建的子窗口之上。您还需要将菜单放在子窗口中,而不是放在父窗体中。
看看这篇文章和这个。
特别是这个:
编辑:添加附加信息
If it is a MDI application and you put controls in the parent window then they will be shown on top of any created child windows. You need to have your menu in a child window also, not on the parent form.
Look at this Article and this.
expecially this:
Edit: Added Additional Information
这里的主要技巧是将子窗体视为控件。您将像任何其他控件一样创建子窗体。当您使用此方法时,您必须将其 TopLevel 设置为 false - 否则它将不起作用。
以下代码行用于创建子表单:
更多详细信息此处
The main trick here is to treat child forms as Controls. You'll create a child form just like any other control. When you use this method, you have to set it's TopLevel to false - otherwise it won't work.
The following lines of code are used to create a child form:
more details here
@Hans Passant 有正确的答案,但您也可以通过根本不使用 MDI 表单来解决您的问题。一些选项:
Parent
属性设置为菜单表单来启动它前面的子表单,或者不过,这两者都需要对您的 UI 代码进行重大更改。
@Hans Passant has the correct answer, but you could also solve your issue by not using MDI forms at all. Some options:
Parent
property to the menu form, orBoth of these would require significant changes to your UI code, though.
非常简单
在 mdi 表单之后创建新表单(frm_chiled_mdi),并根据需要装饰它(如按钮、图片、标签等)
将其加载到MDI表单加载
frm_chiled_mdi的表单加载编码
Its Very Simple
Create new form (frm_chiled_mdi) after mdi form, and decorate it as you wish (like button, picture, label etc.)
Load it on MDI Form Load
form load coding of frm_chiled_mdi
该窗体似乎是其他子控件的同级控件。您必须将其作为该窗口的子窗口打开吗?难道它不能像一个非模式对话框而不是该主窗体的子窗口吗?
如果它必须位于主窗体中并且是这些控件的同级控件,那么您将必须设置它的 Z 顺序。没有相应的属性,因此您必须查看 Win32 API 调用
SetWindowPos
:并像这样调用它:
It appears as though that form is a sibling of those other child controls. Do you have to open it as a child of that window? Can't it be like a non-modal dialog box and not a child window of that main form?
If it has to be within that main form and a sibling of those controls, then you're going to have to set the Z-Order of it. There's no property for that, so you're going to have to look toward the Win32 API call,
SetWindowPos
:And call it something like this:
显示每个子窗体后,调用 BringToFront()。或者,将其挂接到每个子表单的 OnLoad 方法:
Call BringToFront() on each child form after showing them. Alternately, hook it to each child form's OnLoad method:
我遇到了这个问题并通过以下方式解决了它:
I had this problem and solved it this way:
我遇到了同样的问题,并且找到了最好的解决方案。首先,您需要在面板中移动控件。添加一个“MdiChildActivate”事件并编写此内容,
I had the same issue and I have found the best solution for it. First of all you need to shift your controls in a panel. The add a "MdiChildActivate" event and write this,