VB编程Timer控件实例幼儿识字卡片-35_彭世瑜_新浪博客

网友投稿 546 2022-05-28

运行效果:

程序代码:

Dim myarray(10) As String     '定义全局变量,文字数组

Dim i As Integer

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 37 Then          '键盘按键左边←

Call Image1_Click

ElseIf KeyCode = 39 Then      '键盘按键右边→

Call Image2_Click

End If

End Sub

Private Sub Form_Load()     '定义文字数组,初始化timer控件、索引值i

Timer1.Enabled = fasle

Timer1.Interval = 100

myarray(0) = "大": myarray(1) = "小": myarray(2) = "多": myarray(3) = "少"

myarray(4) = "前": myarray(5) = "后": myarray(6) = "左": myarray(7) = "右"

myarray(8) = "中": myarray(9) = "上": myarray(10) = "下"

Label1.Left = -3800

i = -1

Call Image2_Click

End Sub

Private Sub Image1_Click()   '移动到上一个字

If i > 0 Then

i = i - 1

Label1 = myarray(i)

End If

Timer1.Enabled = True

VB编程:Timer控件实例幼儿识字卡片-35_彭世瑜_新浪博客

Label1.Left = -4000

End Sub

Private Sub Image2_Click()   '移动到下一个字

If i < 10 Then

i = i + 1

Label1 = myarray(i)

End If

Timer1.Enabled = True

Label1.Left = -4000

End Sub

Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Image1.MousePointer = 99

Image1.MouseIcon = LoadPicture("c:\windows\cursors\harrow.cur")

End Sub

Private Sub Image3_Click()

Me.WindowState = vbMinimized    '最小化窗口,需要把showintaskbar属性设置为true

End Sub

Private Sub Image3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Image3.MousePointer = 99

Image3.MouseIcon = LoadPicture("c:\windows\cursors\harrow.cur")

End Sub

Private Sub Image4_Click()

End

End Sub

Private Sub Image4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Image4.MousePointer = 99

Image4.MouseIcon = LoadPicture("c:\windows\cursors\harrow.cur")

End Sub

'Timer控件实现文字移动效果,如果移动到中间位置就停止。

Private Sub Timer1_Timer()

If Label1.Left < 5000 Then

Label1.Left = Label1.Left + 200

Else

Label1.Left = -4000

End If

If Label1.Left > 1560 And Label1.Left < 1660 Then

Timer1.Enabled = False

End If

End Sub

学习总结:

1、harrow.cur为windowsXP的系统图标,windows7中没有,要在win7中运行则需要修改成其他图标,否则报错。

2、方向键的键盘码keycode如下:

keycode 37 = Left ←

keycode 38 = Up ↑

keycode 39 = Right →

keycode 40 = Down ↓

3、如果使用if...else语句,else遵循就近原则。

Windows

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:一条SQL更新语句的执行过程
下一篇:Unity零基础到入门 ☀️| Time(时间)和Input键盘及鼠标输入方法
相关文章