Can you show the coding needed to disable the enter key on a textedit box or at the form level?

This form is using multi-line textedit boxes and I would like to prevent the user from pressing the enter key from jumping to the next line in the textedit boxes.

有帮助吗?

解决方案

You would add a handler to the text box's "KeyDown" event and use KeyEventArgs.SuppressKeyPress -- see :

http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.suppresskeypress.aspx#Y0

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, _
        ByVal e As System.Windows.Forms.KeyEventArgs) _
        Handles TextBox1.KeyDown
    If e.KeyCode = Keys.Enter Then
        e.SuppressKeyPress = True
    End If
End Sub

Text boxes also have a .ReadOnly property which can be set programatically if you need to temporarily (or permanently) prevent the user from changing the content of the box (ie: for display only).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top