Change Tab order by code in a MFC Dialog

ぃ、小莉子 提交于 2020-02-03 05:35:05

问题


I created a control by code in the OnInitDialog, but i cannot find any way to change the tab order of the dialog by code.

Anyone have any idea on how to do this?


回答1:


The tab order of controls on a dialog is governed by the Z-Order of those controls. So, to change the tab order, change the z-order positioning of the relevant controls.

You can change the z-order by using SetWindowPos. See this, for example.




回答2:



First Option

use ctrl+d on resource view in visual studio. and change tab order


Other option

An easier solution is change the sequence of controls in .rc file...that will change your tab order and z order both.

For Eg. this dialog will have Tab Order IDOK first, then IDCANCEL

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
END

now if you change it to

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
END

This will have Tab Order IDCANCEL first then IDOK



来源:https://stackoverflow.com/questions/4163156/change-tab-order-by-code-in-a-mfc-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!