Make the Cursor Work in a TextBox

One of the more irritating bugs in VBCE is the bug where the cursor keys don't work in a text box. Not only that, only the KeyUp event fires when one of the cursor keys is pressed, the KeyDown does not. This limits the routines below in that when the cursor key is held down to repeat the keypress, VBCE does not fire multiple KeyUps, as the key has not been let up yet. This means that the user will have to press the key again and again to make the cursor move multiple times.

To use the 4 routines below (ArrowUp, ArrowDown, ArrowLeft, and ArrowRight) simply place the following code in the TextBox's KeyUp Event.

NOTE: This code below requires the VBCE Misc Utility control (free) to operate.

The Shift is checked because when the Shift Key, Ctrl Key, or Alt Key is also pressed with the cursor key, the cursor will move in the TextBox.

Next, place the routines below in the form module or if you are using a standard module, you can place them there for better code reuse.

The reason that we need the VBCE Misc Utility control is that SendMessage is the only way to determine what line we are on and how many charaters the previous or next line has.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.