Pressing enter in Textbox - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pressing enter in Textbox

saphirothsaphiroth Posts: 5Member
How can I make the program do something when a person presses enter after pressing the Enter key on the keyboard? What does the textbox need to handle a Enter key press event?

Thanx

Comments

  • HyBRiD_HeLLHyBRiD_HeLL Posts: 7Member
    : How can I make the program do something when a person presses enter after pressing the Enter key on the keyboard? What does the textbox need to handle a Enter key press event?
    :
    : Thanx
    :


    If Keys.Enter Then :)
    -Simple isn't it:))
  • BaldusariusBaldusarius Posts: 162Member
    Handle the KeyPress event of the TextBox. If you try to handle it in the KeyDown event, you'll get an annoying system beep.

    [code]Private Sub TextBox1_KeyPress(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles _
    TextBox1.KeyPress

    If e.KeyChar = Convert.ToChar(Keys.Enter) Then

    DoSomething();

    'This tells the system not to process
    'the key, as you've already taken care
    'of it
    e.Handled = True
    End If

    End Sub[/code]


    : How can I make the program do something when a person presses enter after pressing the Enter key on the keyboard? What does the textbox need to handle a Enter key press event?
    :
    : Thanx
    :

  • BaldusariusBaldusarius Posts: 162Member
    KeyPressEventArgs does not have a property that returns a value from the Keys enumeration.

    I'm assuming you are directing him to use the KeyDown event, which has a parameter of type KeyEventArgs. Although it would be more convenient to use that event because no conversion is required to use the Keys enumeration, you get an annoying system beep if you try to handle the enter key there. Most people would not be happy with that, so the more correct answer is to handle KeyPress.

    : : How can I make the program do something when a person presses enter after pressing the Enter key on the keyboard? What does the textbox need to handle a Enter key press event?
    : :
    : : Thanx
    : :
    :
    :
    : If Keys.Enter Then :)
    : -Simple isn't it:))
    :

Sign In or Register to comment.