我在key_press中写了如下代码:
为了只能输入数字
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
If KeyAscii <> 8 And (KeyAscii < 46 Or KeyAscii > 57) Then
Beep()
KeyAscii = 0
End If
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
...全文
735打赏收藏
在combobox中禁止某些字符输入,为什么不成功?
我在key_press中写了如下代码: 为了只能输入数字 Dim KeyAscii As Short = Asc(eventArgs.KeyChar) If KeyAscii 8 And (KeyAscii 57) Then Beep() KeyAscii = 0 End If If KeyAscii = 0 Then eventArgs.Handled = True End If
要只能输入数字可以用以下方法:
private sub Combo1_TextChanged(....)
if not isnumeric(combo1.text) then
beep
combo1.text=combo1.text.SubString(0,len(combo1.text)-1)
end if
sub
同意 Latitude(Henry)说的,
我以前做树状节点的时候就是那样做的,以便修改节点的值。设置一下visible属性,赋值等。
在textbox里面就好处理了。
下面的示例创建一个 TextBox 控件。keypressed 方法使用 KeyChar 属性检查是否按了 ENTER 键。如果按了 ENTER 键,则 Handled 属性设置为 true,表示此事件已处理。
[Visual Basic]
Imports System
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Public Sub New()
Dim tb As New TextBox()
Me.Controls.Add(tb)
AddHandler tb.KeyPress, AddressOf keypressed
End Sub 'New
Sub keypressed(ByVal o As [Object], ByVal e As KeyPressEventArgs)
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
e.Handled = True
End If
End Sub 'keypressed
Public Shared Sub Main()
Application.Run(New Form1())
End Sub 'Main
End Class 'Form1