重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
每个textbox都有KeyPress事件(event),每次用户输入一个字符时检测,如不满足则清空
在桦川等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站制作 网站设计制作定制网站开发,公司网站建设,企业网站建设,高端网站设计,营销型网站建设,外贸网站制作,桦川网站建设费用合理。
我现在不在vs下,你可以找到这个面板,绑定相应的函数
比如只能显示数字
Private Sub NumBox_KeyPress(KeyAscii As Integer)
If Not IsNumeric(NumBox.Text) Then
NumBox.Text = ""
End If
End Sub
只能显示英语(a-z 97-122; A-Z 65-90; 8(退格)和13(换行))
Private Sub EngBox_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = 97 And KeyAscii=122) Or (KeyAscii = 90 And KeyAscii=65) Or = 8 Then
EngBox.Text = ""
End If
End Sub
只能显示汉字(汉字的ASCII值要么小于0,要么是8(退格)和13(换行))
Private Sub ChineseBox_KeyPress(KeyAscii As Integer)
If Not KeyAscii 0 Or KeyAscii = 8 Or KeyAscii = 13 Then
ChineseBox.Text=""
End If
End Sub
做了一些小修改,不明白请及时追问,满意敬请采纳,O(∩_∩)O谢谢
第一部、先定义一个单元格操作变量,如下
Dim cellEdit As DataGridViewTextBoxEditingControl = Nothing
第二部、然后在在控件的EditingControlShowing事件中添加入下代码,参考如下:
Private Sub DataGridView3_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView3.EditingControlShowing
cellEdit = CType(e.Control, DataGridViewTextBoxEditingControl)
cellEdit.SelectAll()
AddHandler cellEdit.KeyPress, AddressOf dataGridView3_KeyPress
End Sub
第三部:在要控制的列加入控件键盘按钮的代码,如下面ROLL列是要控制的列
Private Sub dataGridView3_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles DataGridView3.KeyPress
Dim i As Integer = DataGridView3.CurrentCellAddress.X
Dim ColumnName As String = DataGridView3.Columns(i).Name
If (ColumnName = "rollno") Then
If Not Char.IsDigit(e.KeyChar) And e.KeyChar Chr(8) Then
e.Handled = True
End If
End If
End Sub
以下是只能输入数字和小数点,并且小数点只能输入一次
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char.IsDigit(e.KeyChar) or e.KeyChar = Chr(8) or e.KeyChar = "." Then
If e.KeyChar = "." And InStr(TextBox1.Text, ".") 0 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub