Gali
Gali

Reputation: 14953

how to press [Enter] catch the Enter but not to Fall line?

how to press Enter - catch the Enter but not to Fall line ?

for example, i have this:

 private void txtPlace_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
               // do somthing
            }
        }

and i don't want to Fall line

i work on Windows-Mobile - C#

thanks in advance

Upvotes: 0

Views: 185

Answers (2)

SwissGuy
SwissGuy

Reputation: 565

Checkout my answer from this Post:

Check when arrow key are pressed

You have to activate your KeyPreview event to true to listen to your keypress Event

So for your problem:

    Private Sub frm_YourForm(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
        e.Handled = True
    End If
End Sub

Upvotes: 2

Werner
Werner

Reputation: 1311

Try

if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; }

Upvotes: 0

Related Questions