Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you bring a control to front in mfc

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).

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).

like image 633
Tim Erickson Avatar asked Oct 01 '08 22:10

Tim Erickson


2 Answers

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.

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.

like image 158
ryan_s Avatar answered Sep 17 '22 18:09

ryan_s


In Visual Studio 6.0 do the following.

Open the dialog screen (in designer view)

Press 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...)

like image 43
Senthil Avatar answered Sep 20 '22 18:09

Senthil