以下是只能輸入數(shù)字和小數(shù)點,并且小數(shù)點只能輸入一次

成都做網(wǎng)站、成都網(wǎng)站設(shè)計、成都外貿(mào)網(wǎng)站建設(shè)服務團隊是一支充滿著熱情的團隊,執(zhí)著、敏銳、追求更好,是創(chuàng)新互聯(lián)的標準與要求,同時竭誠為客戶提供服務是我們的理念。創(chuàng)新互聯(lián)建站把每個網(wǎng)站當做一個產(chǎn)品來開發(fā),精雕細琢,追求一名工匠心中的細致,我們更用心!
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
第一部、先定義一個單元格操作變量,如下
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 ComboBox1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
Select Case e.KeyValue
Case 48 To 57
Case Keys.Enter
ComboBox1.Items.Add(ComboBox1.Text)
Case Else
ComboBox1.Text = ComboBox1.Text.Remove(ComboBox1.Text.Length - 1, 1)
ComboBox1.SelectionStart = ComboBox1.Text.Length
e.Handled = True
End Select
End Sub
'--------------------
百度VB2010(VB.NET)吧建設(shè)發(fā)展中,需要你的支持和幫助!!!
快加入我們吧!發(fā)表你的疑問,經(jīng)驗,程序,分享..
讓我們共同進步!
Option Explicit On
Option Strict On
Imports System
Module Program
Sub Main()
Dim s As String
Dim strs As String()
Dim fz,fm,n,m,t As Long
Console.Write("請輸入一個小數(shù):")
s=Console.ReadLine().Trim()
strs=s.Split("."C)
fz=CLng(strs(0))
fm=CLng(Math.Pow(10,strs(1).Length))
fz=fz*fm+CLng(strs(1))
n=fz
m=fm
While n Mod m0
t=n Mod m
n=m
m=t
End While
fz\=m
fm\=m
Console.WriteLine("{0}={1}/{2}",s,fz,fm)
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
End Module
input type="text" maxlength="11" /這是控制最大輸入字數(shù)至于不能少于11個字,需要在點擊保存按鈕時,通過.length來控制
標題名稱:vb.net輸入數(shù)字,vb輸入代碼
分享路徑:http://chinadenli.net/article26/heodcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、電子商務、軟件開發(fā)、品牌網(wǎng)站制作、營銷型網(wǎng)站建設(shè)、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)