visual-studio 如何在 mfc 中将控件置于前端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/160105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:41:59  来源:igfitidea点击:

How can you bring a control to front in mfc

visual-studiovisual-c++mfc

提问by Tim Erickson

How do you change controls' Z-order in MFC at design time- i.e. I can't use SetWindowPos or do this at runtime - I want to see the changed z-order in the designer (even if I have to resort to direct-editing the .rc code).

您如何在设计时更改 MFC控件的 Z 顺序- 即我不能使用 SetWindowPos 或在运行时执行此操作 - 我想在设计器中看到更改的 z 顺序(即使我不得不求助于直接 -编辑 .rc 代码)。

I have an MFC dialog to which I am adding controls. If there is overlap between the edges of the controls, I want to bring one to the front of the other. In Windows Forms or WPF, etc. I can Bring to Front, Send to Back, Bring Forward, Send Back. I don't find these options in MFC, nor can I tell how it determines what is in front, as a control just added is often behind a control that was there previously. How can I manipulate the Z-order in MFC? Even if I have to manipulate the .rc file code directly (i.e. end-run around the designer).

我有一个 MFC 对话框,我正在向其中添加控件。如果控件的边缘之间有重叠,我想将一个放在另一个的前面。在 Windows 窗体或 WPF 等中,我可以将其置于前面、发送到后面、向前、向后发送。我在 MFC 中找不到这些选项,也无法说明它如何确定前面的内容,因为刚添加的控件通常位于先前存在的控件后面。如何在 MFC 中操作 Z 顺序?即使我必须直接操作 .rc 文件代码(即围绕设计器结束运行)。

采纳答案by ryan_s

I think the control in front will be the last control that occurs in the rc file. In other words, the dialog editor will draw each control as it is encountered from top to bottom in the rc file, overlapping them when necessary.

我认为前面的控件将是 rc 文件中出现的最后一个控件。换句话说,对话框编辑器将在 rc 文件中从上到下绘制每个控件,并在必要时将它们重叠。

You can edit the rc file to reorder them, or you can change the tab order in the editor, which does the same thing since tab order is also set based on the order that the controls occur in the file. To my knowledge MFC doesn't offer any other way of layering overlapping controls at design time.

您可以编辑 rc 文件以对它们重新排序,或者您可以在编辑器中更改 Tab 键顺序,这样做的作用相同,因为 Tab 键顺序也是根据控件在文件中出现的顺序设置的。据我所知,MFC 在设计时不提供任何其他分层重叠控件的方法。

回答by Senthil

In Visual Studio 6.0 do the following.

在 Visual Studio 6.0 中执行以下操作。

Open the dialog screen (in designer view)

打开对话框屏幕(在设计器视图中)

Press Ctrl + D

按 Ctrl + D

The tab orders will be shown for each control

将为每个控件显示选项卡顺序

Start clicking controls in the tab order you expect to see in run-time (ie., the control on which you click first will have tab order set to 1 and so on...)

按您希望在运行时看到的 Tab 键顺序开始单击控件(即,您首先单击的控件将 Tab 键顺序设置为 1,依此类推...)

回答by Adam Pierce

GetDlgItem(IDC_MYCONTROL)->SetWindowPos(HWND_TOP,
                                        0, 0, 0, 0,
                                        SWP_NOMOVE | SWP_NOSIZE);

回答by Adam Pierce

Actually, if you want to do this in the resource editor, you can just cut the item and then paste it back as a quick and dirty solution. Just Ctrl-X then Ctrl-V.

实际上,如果您想在资源编辑器中执行此操作,您只需剪切该项目,然后将其粘贴回作为快速而肮脏的解决方案。只需 Ctrl-X 然后 Ctrl-V。

Editing the RC file will also work.

编辑 RC 文件也将起作用。

回答by linquize

GetDlgItem(IDC_CONTROL1)->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)

回答by Franci Penov

You can use CWnd::SetWindowPos()to control the Z order of your controls, without changing their position in the parent window.

您可以使用CWnd::SetWindowPos()来控制控件的 Z 顺序,而无需更改它们在父窗口中的位置。

回答by jussij

In the MSVC 2005dialog resource editor there is an option to set the tab order. In MSVC 2005it is found on the Format, Tab Ordermenu.

MSVC 2005对话框资源编辑器中,有一个选项可以设置 Tab 键顺序。在MSVC 2005 中,它位于格式、选项卡顺序菜单上。

The tab order displayed by this menu option is the same order in which the controls are written to the resource file.

此菜单选项显示的 Tab 键顺序与控件写入资源文件的顺序相同。