0

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

udondan
  • 57,263
  • 20
  • 190
  • 175
Gali
  • 14,511
  • 28
  • 80
  • 105

2 Answers2

2

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
Community
  • 1
  • 1
SwissGuy
  • 565
  • 1
  • 6
  • 18
0

Try

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

Werner
  • 1,229
  • 1
  • 10
  • 24