Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC: How to move between Edit Controls with the arrow keys?

MFC: How to move between Edit Controls with the arrow keys?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++questionlearning
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Davex_
    wrote on last edited by
    #1

    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

    R 2 S 3 Replies Last reply
    0
    • D Davex_

      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

      R Offline
      R Offline
      Roger Stewart
      wrote on last edited by
      #2

      TAB goes forward in the taborder, SHIFT+TAB goes backwards. Roger Stewart "I Owe, I Owe, it's off to work I go..."

      1 Reply Last reply
      0
      • D Davex_

        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

        2 Offline
        2 Offline
        224917
        wrote on last edited by
        #3

        SHIFT+TAB


        greatest thing is to do wot others think you cant
        suhredayan@omniquad.com

        1 Reply Last reply
        0
        • D Davex_

          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

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • S 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

            D Offline
            D Offline
            Davex_
            wrote on last edited by
            #5

            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

            R 1 Reply Last reply
            0
            • D Davex_

              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

              R Offline
              R Offline
              Roger Allen
              wrote on last edited by
              #6

              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 here

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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups