vb.net只能输数字 vb文本框只能输入数字
vb.net 让相应的textbox中只能输入“中文字符、英文、数字”
每个textbox都有KeyPress事件(event),每次用户输入一个字符时检测,如不满足则清空
我们提供的服务有:做网站、成都网站制作、微信公众号开发、网站优化、网站认证、古浪ssl等。为上千多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的古浪网站制作公司
我现在不在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谢谢
如何在VB.NET 中限制文本框中只能输入数字
以下是只能输入数字和小数点,并且小数点只能输入一次
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
VB.NET中让Textbox只能输入数字
Public Class Form Inherits System Windows Forms Form
#Region Windows 窗体设计器生成的代码
Public Sub New() MyBase New()
该调用是 Windows 窗体设计器所必需的 InitializeComponent()
在 InitializeComponent() 调用之后添加任何初始化
End Sub
窗体重写 dispose 以清理组件列表 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (ponents Is Nothing) Then ponents Dispose() End If End If MyBase Dispose(disposing) End Sub
Windows 窗体设计器所必需的 Private ponents As System ComponentModel IContainer
注意: 以下过程是 Windows 窗体设计器所必需的 可以使用 Windows 窗体设计器修改此过程 不要使用代码编辑器修改它 Friend WithEvents TextBox As System Windows Forms TextBox Private Sub InitializeComponent() Me TextBox = New System Windows Forms TextBox Me SuspendLayout() TextBox Me TextBox Location = New System Drawing Point( ) Me TextBox Name = TextBox Me TextBox TabIndex = Me TextBox Text = Form Me AutoScaleBaseSize = New System Drawing Size( ) Me ClientSize = New System Drawing Size( ) Me Controls Add(Me TextBox ) Me Name = Form Me Text = Form Me ResumeLayout(False)
End Sub
#End Region Dim str As String =
lishixinzhi/Article/program/net/201311/13841
VB.NET下,让textbox只能输入数字,小数点,和负号,我的代码哪里有错?
private str as string 'str最好定义到外面
Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
Dim d As Double
If Double.TryParse(TextBox1.Text, d) Or TextBox1.Text = "-" Or TextBox1.Text.Trim() = "" Then
str = TextBox1.Text
Else
TextBox1.Text = str
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.Focus()
End If
End Sub
VB.NET中的DATAGRIDVIEW怎样只能在表格中输入数字呢
第一部、先定义一个单元格操作变量,如下
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
网站标题:vb.net只能输数字 vb文本框只能输入数字
文章源于:http://scyanting.com/article/doogdih.html