以下是只能输入数字和小数点,并且小数点只能输入一次
成都做网站、成都网站设计、成都外贸网站建设服务团队是一支充满着热情的团队,执着、敏锐、追求更好,是创新互联的标准与要求,同时竭诚为客户提供服务是我们的理念。创新互联建站把每个网站当做一个产品来开发,精雕细琢,追求一名工匠心中的细致,我们更用心!
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)吧建设发展中,需要你的支持和帮助!!!
快加入我们吧!发表你的疑问,经验,程序,分享..
让我们共同进步!
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("请输入一个小数:")
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" /这是控制最大输入字数至于不能少于11个字,需要在点击保存按钮时,通过.length来控制