How to implement Tab order to the controls in a MFC Dialog box
-
Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!
-
Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!
-
Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!
Hi, LayoutMenu->TabOrder
-
Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!
If you are using resource editor, you can set the tab order there. It is available in "Layout" menu in VC6 and "Format" menu VC9. Shortcut key is Ctrl + D (in VC6 keyboard shortcut map). Then you can see the tab order indication for all controls. You can click on each controls to sequence. If you are creating the controls dynamically, the creation order sets the tab order. You can change it by using SetWindowPos().
- ns ami -
-
If you are using resource editor, you can set the tab order there. It is available in "Layout" menu in VC6 and "Format" menu VC9. Shortcut key is Ctrl + D (in VC6 keyboard shortcut map). Then you can see the tab order indication for all controls. You can click on each controls to sequence. If you are creating the controls dynamically, the creation order sets the tab order. You can change it by using SetWindowPos().
- ns ami -
Hi ns Ami, I am creating dynamic edit box in Group Box. My current Tab order is Group Box, OK, Cancel button. Now I want tab order as: Group box-> Edit Box 1 -> Edit Box 2 -> Edit Box 3 -> OK -> Cancel. How can i achieve this? do you have any idea? Regards, Anshul
-
Hi ns Ami, I am creating dynamic edit box in Group Box. My current Tab order is Group Box, OK, Cancel button. Now I want tab order as: Group box-> Edit Box 1 -> Edit Box 2 -> Edit Box 3 -> OK -> Cancel. How can i achieve this? do you have any idea? Regards, Anshul
I presume that "dynamic edit box" means you are creating edit box dynamically at run time. If so, you can use SetWindowPos API to set the Z-order of edit control. You will get more information from the API documentation. The parameter hWndInsertAfter (or pWndInsertAfter in the case of MFC) can be the window handle of control, which is needed to be before in tab order. For example, m_edit2.SetWindowPos( &m_edit1, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZER | SWP_NOACTIVATE ); This will set the tab order as edit1 -> edit2. Hope this info will help.
- ns ami -
-
I presume that "dynamic edit box" means you are creating edit box dynamically at run time. If so, you can use SetWindowPos API to set the Z-order of edit control. You will get more information from the API documentation. The parameter hWndInsertAfter (or pWndInsertAfter in the case of MFC) can be the window handle of control, which is needed to be before in tab order. For example, m_edit2.SetWindowPos( &m_edit1, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZER | SWP_NOACTIVATE ); This will set the tab order as edit1 -> edit2. Hope this info will help.
- ns ami -
Hi Ami, I am creating edit box in Group box as:
#define ID_CURRENT_SN_EDIT 2000
m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
int pointY = 0;
int i = 0;for (int x = 0; x < m_vecpData->size(); x++, i++)
{
pointY = 30 + (i * 35);
m_ceEdit = new CEdit;
m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY | WS_TABSTOP, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
m_ceEdit->SetWindowText(m_vecpData->at(x).c_str());
m_ceEdit->SetWindowPos(m_gbGroupBox, HWND_BOTTOM , 10, pointY, 130, pointY + 25, SWP_NOSIZE); // This line is not working.:confused:
m_ceEdit->ShowWindow(SW_SHOWNORMAL);
} -
Hi Ami, I am creating edit box in Group box as:
#define ID_CURRENT_SN_EDIT 2000
m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
int pointY = 0;
int i = 0;for (int x = 0; x < m_vecpData->size(); x++, i++)
{
pointY = 30 + (i * 35);
m_ceEdit = new CEdit;
m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY | WS_TABSTOP, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
m_ceEdit->SetWindowText(m_vecpData->at(x).c_str());
m_ceEdit->SetWindowPos(m_gbGroupBox, HWND_BOTTOM , 10, pointY, 130, pointY + 25, SWP_NOSIZE); // This line is not working.:confused:
m_ceEdit->ShowWindow(SW_SHOWNORMAL);
}In this case the tab order will be same as the creation order. So no need to set the Z-order again. Anyway, is this a compilable code? Argument count of SetWindowPos seems as wrong. Note that you are creating edit control as child of that GroupBox (a static control, i think). In that case the tab key navigation will not enter to the controls inside the GroupBox. Applying WS_EX_CONTROLPARENT style to GroupBox will help you. For instance, m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT );
- ns ami -
-
In this case the tab order will be same as the creation order. So no need to set the Z-order again. Anyway, is this a compilable code? Argument count of SetWindowPos seems as wrong. Note that you are creating edit control as child of that GroupBox (a static control, i think). In that case the tab key navigation will not enter to the controls inside the GroupBox. Applying WS_EX_CONTROLPARENT style to GroupBox will help you. For instance, m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT );
- ns ami -
This is my modified compilable code but tab order is not working as GRPBox -> Edit 1 -> Edit 2 -> Edit 3 -> OK -> CANCEL.
It is still working as **GRPBox -> OK -> CANCEL.**
#define ID_CURRENT_SN_EDIT 1003
m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT);m_btnOK = (CButton*)GetDlgItem(IDC_OK);
m_btnCancel = (CButton*)GetDlgItem(IDC_CANCEL);int pointY = 0;
int i = 0;for (int x = 0; x < m_vecpData->size(); x++, i++)
{
pointY = 30 + (i * 35);
m_ceEdit = new CEdit;
m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
m_ceEdit>SetWindowText(m_vecpData->at(x).c_str());
int nCtlrID = ID_CURRENT_SN_EDIT + i;if (x > 0)
{
CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1);
m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
}
m_ceEdit->ShowWindow(SW_SHOWNORMAL);
}Any Help or Suggestion!! I do not know what to do now.
-
This is my modified compilable code but tab order is not working as GRPBox -> Edit 1 -> Edit 2 -> Edit 3 -> OK -> CANCEL.
It is still working as **GRPBox -> OK -> CANCEL.**
#define ID_CURRENT_SN_EDIT 1003
m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT);m_btnOK = (CButton*)GetDlgItem(IDC_OK);
m_btnCancel = (CButton*)GetDlgItem(IDC_CANCEL);int pointY = 0;
int i = 0;for (int x = 0; x < m_vecpData->size(); x++, i++)
{
pointY = 30 + (i * 35);
m_ceEdit = new CEdit;
m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
m_ceEdit>SetWindowText(m_vecpData->at(x).c_str());
int nCtlrID = ID_CURRENT_SN_EDIT + i;if (x > 0)
{
CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1);
m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
}
m_ceEdit->ShowWindow(SW_SHOWNORMAL);
}Any Help or Suggestion!! I do not know what to do now.
:) Well, you missed WS_TABSTOP style.
AJ83 wrote:
m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
And the following is not needed...
AJ83 wrote:
if (x > 0) { CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1); m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE ); } m_ceEdit->ShowWindow(SW_SHOWNORMAL);
- ns ami -
-
:) Well, you missed WS_TABSTOP style.
AJ83 wrote:
m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
And the following is not needed...
AJ83 wrote:
if (x > 0) { CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1); m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE ); } m_ceEdit->ShowWindow(SW_SHOWNORMAL);
- ns ami -
Hey Ami,
**Thanks a lot for your valuable suggestion. It is working now. great :) !!!**
Now my another task is: There is one Static GRPbox which has been created in CFormView by using ToolBox. Now in Static Groupbox, I am creating "n" number of dynamic GrpBox. In Dynamic GrpBox, I am creating dynamic Edit Box (few are READ ONLY too). Now I have to set taborder for that also. Any suggestion on this.? Regards, Anshul -
Hey Ami,
**Thanks a lot for your valuable suggestion. It is working now. great :) !!!**
Now my another task is: There is one Static GRPbox which has been created in CFormView by using ToolBox. Now in Static Groupbox, I am creating "n" number of dynamic GrpBox. In Dynamic GrpBox, I am creating dynamic Edit Box (few are READ ONLY too). Now I have to set taborder for that also. Any suggestion on this.? Regards, Anshul -
I believe that, since you could understand your first solution well, you can implement this easily. :) Or, are you in any trouble with that?
- ns ami -
Well, In first round it is working but once it comes to OK or CANCEL button is not going back to edit box. I am trying for that... I will post code after few minutes or if you do have idea of why is it not coming back to edit box, you can let me know.. Regards, Anshul
-
Well, In first round it is working but once it comes to OK or CANCEL button is not going back to edit box. I am trying for that... I will post code after few minutes or if you do have idea of why is it not coming back to edit box, you can let me know.. Regards, Anshul
-
open your dialog in the IDE, Press "Ctrl + D". This will display the current tab order. Click on each controls in the order in which you want to set tab-order.