VB中,如何让鼠标箭头永远追不上命令按钮,就是鼠标箭头一接近命令按钮,就随机跳到另一个位置,要代码
3个回答
展开全部
把这个代码输入到记事本里面,再存储成.frm格式,用vb打开,就可以了。
VERSION 5.00
Begin VB.Form game1
BorderStyle = 1 'Fixed Single
Caption = "game"
ClientHeight = 3030
ClientLeft = 45
ClientTop = 375
ClientWidth = 4560
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3030
ScaleWidth = 4560
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "点"
Height = 300
Left = 600
TabIndex = 0
Top = 840
Width = 300
End
Begin VB.Label Label3
BorderStyle = 1 'Fixed Single
Caption = "DBLClick"
ForeColor = &H00E0E0E0&
Height = 255
Left = 2520
TabIndex = 3
Top = 360
Width = 1095
End
Begin VB.Label Label2
BorderStyle = 1 'Fixed Single
Caption = "请您点这个按钮<-----------------"
Height = 1455
Left = 960
TabIndex = 2
Top = 720
Width = 1335
End
Begin VB.Label Label1
BorderStyle = 1 'Fixed Single
Caption = "帮助"
Height = 255
Left = 960
TabIndex = 1
Top = 360
Width = 1335
End
End
Attribute VB_Name = "game1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a As Integer
Private Sub Command1_Click()
MsgBox "您赢了", vbOKOnly, "game-01"
End
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
If a = 1 Then
Randomize
Command1.Left = CInt(Rnd * 3000)
Command1.Top = CInt(Rnd * 2600)
End If
End Sub
Private Sub Form_Click()
a = 1
End Sub
Private Sub Form_DblClick()
a = 0
End Sub
Private Sub Form_Load()
a = 1
End Sub
VERSION 5.00
Begin VB.Form game1
BorderStyle = 1 'Fixed Single
Caption = "game"
ClientHeight = 3030
ClientLeft = 45
ClientTop = 375
ClientWidth = 4560
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3030
ScaleWidth = 4560
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "点"
Height = 300
Left = 600
TabIndex = 0
Top = 840
Width = 300
End
Begin VB.Label Label3
BorderStyle = 1 'Fixed Single
Caption = "DBLClick"
ForeColor = &H00E0E0E0&
Height = 255
Left = 2520
TabIndex = 3
Top = 360
Width = 1095
End
Begin VB.Label Label2
BorderStyle = 1 'Fixed Single
Caption = "请您点这个按钮<-----------------"
Height = 1455
Left = 960
TabIndex = 2
Top = 720
Width = 1335
End
Begin VB.Label Label1
BorderStyle = 1 'Fixed Single
Caption = "帮助"
Height = 255
Left = 960
TabIndex = 1
Top = 360
Width = 1335
End
End
Attribute VB_Name = "game1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a As Integer
Private Sub Command1_Click()
MsgBox "您赢了", vbOKOnly, "game-01"
End
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
If a = 1 Then
Randomize
Command1.Left = CInt(Rnd * 3000)
Command1.Top = CInt(Rnd * 2600)
End If
End Sub
Private Sub Form_Click()
a = 1
End Sub
Private Sub Form_DblClick()
a = 0
End Sub
Private Sub Form_Load()
a = 1
End Sub
追问
非常感谢
追答
不用谢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
完整代码我这里没有VB不能给你,但是可以给你部份代码和思路。
让鼠标接近命令按钮就让命令按钮做出反应的思路:
在VB中控件有一个mouse_move事件在其中加入响应代码
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
在这里加入改变Command1的top、Left等位置属性就行了
End Sub
让鼠标接近命令按钮就让命令按钮做出反应的思路:
在VB中控件有一个mouse_move事件在其中加入响应代码
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
在这里加入改变Command1的top、Left等位置属性就行了
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim xLeft As Long
Dim yTop As Long
xLeft = Rnd() * Me.Width - 800 '为了防止按钮移出屏幕外,适当减去一个数
yTop = Rnd() * Me.Height - 800
Command1.Move x, y
End Sub
Dim xLeft As Long
Dim yTop As Long
xLeft = Rnd() * Me.Width - 800 '为了防止按钮移出屏幕外,适当减去一个数
yTop = Rnd() * Me.Height - 800
Command1.Move x, y
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询