Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、寧海網(wǎng)站維護(hù)、網(wǎng)站推廣。
Dim s As String = TextBox1.Text
If Not ((Mid(s, Len(s), 1) = "0" And Mid(s, Len(s), 1) = "9") Or (Mid(s, Len(s), 1) = "A" And Mid(s, Len(s), 1) = "Z")) Then
s = Microsoft.VisualBasic.Left(s, Len(s) - 1)
TextBox1.Text = s
TextBox1.SelectionStart = Len(TextBox1.Text)
End If
End Sub
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
有一個(gè)屬性就是設(shè)置只允許輸入指定字符的
如果沒記錯(cuò)的話叫valueOnly
輸入0123456789就可以實(shí)現(xiàn)
以下是只能輸入數(shù)字和小數(shù)點(diǎn),并且小數(shù)點(diǎn)只能輸入一次
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
每個(gè)textbox都有KeyPress事件(event),每次用戶輸入一個(gè)字符時(shí)檢測(cè),如不滿足則清空
我現(xiàn)在不在vs下,你可以找到這個(gè)面板,綁定相應(yīng)的函數(shù)
比如只能顯示數(shù)字
Private?Sub?NumBox_KeyPress(KeyAscii?As?Integer)
If?Not?IsNumeric(NumBox.Text)?Then
NumBox.Text?=?""
End?If
End?Sub
只能顯示英語(yǔ)(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
做了一些小修改,不明白請(qǐng)及時(shí)追問,滿意敬請(qǐng)采納,O(∩_∩)O謝謝
第一部、先定義一個(gè)單元格操作變量,如下
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
本文標(biāo)題:vb.net只輸入數(shù)字 vb如何設(shè)置文本框只能輸入數(shù)字
本文網(wǎng)址:http://jinyejixie.com/article40/hpsoho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、軟件開發(fā)、網(wǎng)站排名、全網(wǎng)營(yíng)銷推廣、外貿(mào)網(wǎng)站建設(shè)、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)