Home>Tips>Surpressing the Enter key

I only want to use word warp. How can I suppress the Enter key?

A MultiLineComboBox handles the enter key in KeyPress event. Therefore, you can suppress the enter key by handling KeyPress event.

Please try the following sample code.

C# Sample Code

Step1: Add your event handler to KeyPress event,

this.MyComboBox.KeyPress += new KeyPressEventHandler(myComboBox_KeyPress);

or create an event hander from the property list.

Step2: Change the KeyPressEventArgs.Handled property to true when KeyChar property is 13(Enter key).

private void myComboBox_KeyPress(object sender, KeyPressEventArgs e)
    if (e.KeyChar == (char)13)
        e.Handled = true;

VB.net Sample Code

Change the KeyPressEventArgs.Handled property to True when KeyChar property is vbCr in your multiline combobox's KeyPress event handler.

Private Sub MyComboBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyComboBox1.KeyPress
    If e.KeyChar = vbCr Then
        e.Handled = True
    End If
End Sub


Copyright (C) YAMAGUCHI Toshinobu All Rights Reserved.