标签:10 KeyAscii End Sub Shift vb Text1 Integer 鼠标
本章介绍和键盘鼠标有光的事件过程
KeyPress事件
当压下键盘上的某个键的时候,将发生KeyPress事件
精确描述: 按下某个键,我们将触发此时拥有焦点的KeyPress 事件。
输入焦点只能位于一个控件上,如果窗体没有活动或者可见的控件,则输入焦点位于窗体。
我们可以利用vb自动生成一个 这样的keypress事件
说明:
- KeyASCII 用于单个控件。 keyAscii 是 所按键的ASCII码
例子
Private Sub Text1_Key Press(KeyAscii As Integer)
if KeyAscii < 48 Or KeyAscii > 57 Then
Beep
KeyAscii = 0
End Sub
只允许输入 0 (48) ~ 9(57)
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
Beep
KeyAscii = 0
End If
KeyAscii = 0
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii >= 65 And KeyAscii <= 122 Then
KeyAscii = 42
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Printer.Print Text3.Text
End If
KeyAscii = 0
学习数据库的时候,视屏介绍了 一个方法叫做 抽象化和实例化比较法
10.1 编写口令程序
Private Sub Form_Load()
Text1.Text = ""
Text1.FontSize = 10
Label1.FontSize 12
Label1.FontBold = True
Label1.FontName = "隶书"
Label1.Caption = "请输入口令"
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Private Sub Text1_KeyPress(KeyAscii As Integer)
Static PWord As String
Static Counter As Integer
Static Numberoftries As Integer
If Numberoftries = 12 Then End
Counter = Counter + 1
PWord = PWord + Chr$(KeyAscii)
KeyAscii = 0
Text1.Text = String$(Counter, "*")
If LCase$(PWord) = "abcd" Then
Text1.Text = ""
PWord = 0
MsgBox "口令正确"
Counter = 0
Print "Continue"
ElseIf Counter = 4 Then
Counter = 0
PWord = ""
Text1.Text = ""
MsgBox "口令对不对,请从星输入"
End If
End Sub
KeyDown KeyUp 事件
KeyDown 和 KeyUp返回的是键盘的状态,
过程的参数用于的那个控件,KeyCode As Integer Shift As Integer
KeyCode 大写字母和小写字母 是一样的, 因为都用一个键盘
SHIFT
转换键 ,shift ctrl AL他 001 010 100
我们可以建立如下过程
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
End Sub
KeyDown 是键盘按下时产生的事件,KeyUp是键盘松开时产生的事件
例子
按下的时候标签显示扫描码,松开的时候被清楚
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Label1.Caption = Str$(KeyCode)
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Label.Caption = ""
End Sub
我们可以用
Const Shift = 1
Const Ctrl = 2
Const Alt = 4
shift And Shift > 0
Shift And Ctrl > 0
Shift And Alt > 0
鼠标事件
单击和双击
按下和放开
按下
MouseDown
松开
MouseUp
移动
MouseMove
参数(Button As Integer,Shift As Integer,x As Single, y As Single)
Button 按下的鼠标键
SHift 表示 shift Ctrl Alt状态
x y 鼠标光标的当前位置
鼠标光标的形状
MousePointer
设置鼠标光标形状
- 对象.MousePoint = 设置值
windows 规则
1. 表示用户可用的功能
拖放
属性
DragMode
DragIcon
手动拖放
自动拖放
标签:10,KeyAscii,End,Sub,Shift,vb,Text1,Integer,鼠标 来源: https://blog.csdn.net/weixin_43401039/article/details/99645651
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。