locked
Different tabbing result between using Tab key and by code RRS feed

  • Question

  • I have a textbox in my vb.net form. After entering data in the textbox and press the tab key, the cursor will move out  of the control. Now, instead of using tab key, I like to use the "Enter key" and I use the  sub below to do the job.

    Private Sub textbox1_KeyPress(sender As System.object, e As System,Windows.Forms.KeyPressEventArgs)  _
                                                                          Handles textBox1.KeyPress
          If e.KeyChar = Microsoft.VisualBasic.Chrw(keys.Return) Then
                      SendKeys.Send("{Tab}")
          End If
    End Sub

    Both ways able to move the cursor out of the textbox.  But, by using the sub(with Enter key), the  content in textbox1 disappear, whereas by using  the tab key from the keyboard, the content can still appear in textbox1.

    I would like to use the sub (with Enter key) method and still with the content in textbox1 not disappear. How can I achieve this?

    Kindly advise.


    TS Lim

    Monday, December 10, 2012 7:31 AM

Answers

  • The content disappears?

    I would have to assume that you set the TextBox.MultiLine to True to get rid of the "ding" noise when someone presses enter.  If you click back in the textbox and press the up arrow, the textbox should scroll up and your text returns.

    You probably want to add e.Handled = True after calling SendKeys.Send().


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by TS Lim Wednesday, December 12, 2012 11:25 PM
    Monday, December 10, 2012 5:41 PM
    Moderator

All replies

  • The content disappears?

    I would have to assume that you set the TextBox.MultiLine to True to get rid of the "ding" noise when someone presses enter.  If you click back in the textbox and press the up arrow, the textbox should scroll up and your text returns.

    You probably want to add e.Handled = True after calling SendKeys.Send().


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by TS Lim Wednesday, December 12, 2012 11:25 PM
    Monday, December 10, 2012 5:41 PM
    Moderator
  • Hi Reed,

    You are right. It is exactly what happened. And by adding e.Handle = True, it did get rid of the "ding" noise.

    Thank you for pointing out the souce of the problem and offer a solution.


    TS Lim

    Wednesday, December 12, 2012 11:25 PM