怎么设计使VB中标签向左,向右手动移动的程序呢

怎么设计使VB中标签向左,向右手动移动的程序呢,第1张

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

If KeyCode = vbKeyLeft And Label1.Left > 0 Then

    Label1.Left = Label1.Left - 120  '按←键使标签向左移动

ElseIf KeyCode = vbKeyRight And Label1.Left < Me.ScaleWidth - Label1.Width Then

    Label1.Left = Label1.Left + 120  '按→键使标签向右移动

End If

End Sub

Private Sub Form_Load()

Me.KeyPreview = True

End Sub

下面就是你想要的程序~~测试通过~~

Dim distance As Integer

Private Sub Command1_Click()

distance = 10 '正数代表右移 数字代表移动的距离

End Sub

Private Sub Command2_Click()

distance = -10 '负数代表左移

End Sub

Private Sub Command3_Click()

distance = 0 '不移

End Sub

Private Sub Timer1_Timer()

Timer1.Interval = 500 '每隔0.5秒移动一下

Shape1.Left = Shape1.Left + distance

End Sub

你要加一个shape控件,三个时间按钮控件,一个timer控件并命名~

Email:fightiger25@163.com索要源代码


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11884735.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存