做一个VB中让label标签在form中上下左右手动移动。
2个回答
展开全部
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 38 'Up
If Label1.Top > 100 Then Label1.Top = Label1.Top - 100
Case 37 'Left
If Label1.Left > 100 Then Label1.Left = Label1.Left - 100
Case 39 'Right
If Label1.Left + Label1.Width < Me.ScaleWidth Then Label1.Left = Label1.Left + 100
Case 40 'Down
If Label1.Top + Label1.Height < Me.ScaleHeight Then Label1.Top = Label1.Top + 100
End Select
End Sub
Select Case KeyCode
Case 38 'Up
If Label1.Top > 100 Then Label1.Top = Label1.Top - 100
Case 37 'Left
If Label1.Left > 100 Then Label1.Left = Label1.Left - 100
Case 39 'Right
If Label1.Left + Label1.Width < Me.ScaleWidth Then Label1.Left = Label1.Left + 100
Case 40 'Down
If Label1.Top + Label1.Height < Me.ScaleHeight Then Label1.Top = Label1.Top + 100
End Select
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Const x = 1000, y = 1000
Dim a As Integer, b As Integer
Private Sub Form_Activate()
With Label1
.AutoSize = True
.Caption = "累啊"
End With
Me.WindowState = vbMaximized
Timer1.Interval = 50
a = 1: b = 1
End Sub
Private Sub Timer1_Timer()
With Label1
If .Top >= Me.ScaleHeight Then a = -1 * a
If .Left >= Me.ScaleWidth Then b = -1 * b
If .Top <= 0 Then a = -1 * a
If .Left <= 0 Then b = -1 * b
.Top = .Top + y * a
.Left = .Left + x * b
End With
End Sub
Const x = 1000, y = 1000
Dim a As Integer, b As Integer
Private Sub Form_Activate()
With Label1
.AutoSize = True
.Caption = "累啊"
End With
Me.WindowState = vbMaximized
Timer1.Interval = 50
a = 1: b = 1
End Sub
Private Sub Timer1_Timer()
With Label1
If .Top >= Me.ScaleHeight Then a = -1 * a
If .Left >= Me.ScaleWidth Then b = -1 * b
If .Top <= 0 Then a = -1 * a
If .Left <= 0 Then b = -1 * b
.Top = .Top + y * a
.Left = .Left + x * b
End With
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询