我想要做一个只能输入数字的自定义控件,但一直没成功,请大虾帮忙(在线等):
代码如下:
Public inputdatatype As String
Public Property Get text() As Variant
text = Text1.text
End PropertyPublic Property Let text(ByVal vNewValue As Variant)
Text1.text = vNewValue
PropertyChanged "text"
End PropertyPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If inputdatatype = "type_number" Then
If KeyCode < 48 Or KeyCode > 105 Or KeyCode > 57 And KeyCode < 96 Then
Text1.text = Left(Text1.text, Len(Text1.text) - 1)
End If
End If
End SubPrivate Sub UserControl_Resize()
Text1.Left = 0
Text1.Top = 0
Text1.Width = UserControl.Width
Text1.Height = UserControl.Height
End Sub
代码如下:
Public inputdatatype As String
Public Property Get text() As Variant
text = Text1.text
End PropertyPublic Property Let text(ByVal vNewValue As Variant)
Text1.text = vNewValue
PropertyChanged "text"
End PropertyPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If inputdatatype = "type_number" Then
If KeyCode < 48 Or KeyCode > 105 Or KeyCode > 57 And KeyCode < 96 Then
Text1.text = Left(Text1.text, Len(Text1.text) - 1)
End If
End If
End SubPrivate Sub UserControl_Resize()
Text1.Left = 0
Text1.Top = 0
Text1.Width = UserControl.Width
Text1.Height = UserControl.Height
End Sub
解决方案 »
- spread 帮助,急需!谢谢!
- 如何在屏幕上画一个正方形
- 二个vb调用sql数据库的connectString和datetime数据类型问题,望大侠指点迷津~~~
- 高手请指教,为何集合的值会是true 和 false
- 如何编程实现MAC与IP的关联?
- 请教各位大虾:如何实现串口通讯,带奇偶效验,以方式二进制收发。谢谢
- 关于open的使用
- 如何在vb程序中使word禁用宏呢,一定给分
- VB打印记录,汇总
- 誰有ActiveReport 1.1.0.85 的注冊文件?50分送上。
- 大小写转换
- 我的程序中用到DAO3.5.DLL,我打了包,但MSJET3.5和VB5DB.DLL没有打包进去,程序运行后提示这两个文件找不到,不能运行.
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Private Sub txtMyText_KeyPress(Keycode As Integer)
If Keycode < 48 Or Keycode > 57 Then
Keycode = 0
End If
end sub