MFC: How to move between Edit Controls with the arrow keys?
-
Hi, I'm doing a little project in MFC. I want to be able to move up and down between my 12 Edit Controls with the arrow keys. The TAB key only goes down, I want to go up too. I'm a beginner and I did not find informations on internet about this. Can someone indicate me to a article or an example on the subject. It must be simple, but my knowledge of MFC is limited. Thanks Dave
-
Hi, I'm doing a little project in MFC. I want to be able to move up and down between my 12 Edit Controls with the arrow keys. The TAB key only goes down, I want to go up too. I'm a beginner and I did not find informations on internet about this. Can someone indicate me to a article or an example on the subject. It must be simple, but my knowledge of MFC is limited. Thanks Dave
TAB goes forward in the taborder, SHIFT+TAB goes backwards. Roger Stewart "I Owe, I Owe, it's off to work I go..."
-
Hi, I'm doing a little project in MFC. I want to be able to move up and down between my 12 Edit Controls with the arrow keys. The TAB key only goes down, I want to go up too. I'm a beginner and I did not find informations on internet about this. Can someone indicate me to a article or an example on the subject. It must be simple, but my knowledge of MFC is limited. Thanks Dave
-
Hi, I'm doing a little project in MFC. I want to be able to move up and down between my 12 Edit Controls with the arrow keys. The TAB key only goes down, I want to go up too. I'm a beginner and I did not find informations on internet about this. Can someone indicate me to a article or an example on the subject. It must be simple, but my knowledge of MFC is limited. Thanks Dave
Hmm. If the edit controls are single line, you can make the arrow keys do this. If they are multi-line (and I'm guessing they aren't), you wouldn't want to. The obvious question is WHY? The use of TAB and Shift-TAB is a perfectly acceptable standard navigation technique. What I'd do if I had to do this is derive from CEdit (CEditWithUpDown), and have it check in OnKeyDown for the up/down arrows, and if they were found, use GetNextDlgTabItem to find the next/previous control, and set focus to that. Steve S
-
Hmm. If the edit controls are single line, you can make the arrow keys do this. If they are multi-line (and I'm guessing they aren't), you wouldn't want to. The obvious question is WHY? The use of TAB and Shift-TAB is a perfectly acceptable standard navigation technique. What I'd do if I had to do this is derive from CEdit (CEditWithUpDown), and have it check in OnKeyDown for the up/down arrows, and if they were found, use GetNextDlgTabItem to find the next/previous control, and set focus to that. Steve S
Thanks, I didn't know the Shift+Tab! But I want to use the arrow keys too, I think it will be easier to navigate between the edit controls and more instinctive. And also, the persons who will use my little program are already used to a similar program that navigates with the arrow keys. My Edit controls are all single line, so I'll do what you suggest Steve, Thanks. By the way, this web site is really nice, it's helping me a lot to learn about MFC and C++. Dave
-
Thanks, I didn't know the Shift+Tab! But I want to use the arrow keys too, I think it will be easier to navigate between the edit controls and more instinctive. And also, the persons who will use my little program are already used to a similar program that navigates with the arrow keys. My Edit controls are all single line, so I'll do what you suggest Steve, Thanks. By the way, this web site is really nice, it's helping me a lot to learn about MFC and C++. Dave
You may be able to do it by overriding the controlling windows PreTranslateMessage function and putting in this code:
if (pMsg->message == WM_KEYDOWN)
{
CWnd *pWnd = GetFocus();
if (pWnd)
{
if (pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
{
switch (wParam)
{
case VK_UP:
pWnd = pWnd->GetNextWindow(GW_HWNDPREV);
if (pWnd)
pWnd->SetFocus();
return TRUE;
case VK_DOWN:
pWnd = pWnd->GetNextWindow(GW_HWNDNEXT);
if (pWnd)
pWnd->SetFocus();
return TRUE;
}
}
}
}
// call the base class hereI just threw this code together after a quick scan of the MSDN. It may work as required. Roger Allen - Sonork 100.10016 Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...