Friday, July 31, 2009

How to make a moving button in Visual Basic 6?

Im very new to VB (this is my thrid day) and I'm trying to figure out how to make a command button that moves around randomly when the mouse cursor hovers over it. I know it's stupid and I'm sure very simple but I'm having a hard time figuring it out any help would be great! Thank you.

How to make a moving button in Visual Basic 6?
HI


PUT A COMMANDBUTTON CALLED "Command1"


AND INTO THE MouseMove EVENT PUT


THE CODE


e = Int((4 - 1 + 1) * Rnd + 1)





If e = 1 Then


Command1.Top = Command1.Top + Int((20 - 10 + 1) * Rnd + 10)


ElseIf e = 2 Then


Command1.Left = Command1.Left + Int((20 - 10 + 1) * Rnd + 10)


ElseIf e = 3 Then


Command1.Top = Command1.Top - Int((20 - 10 + 1) * Rnd + 10)


ElseIf e = 4 Then


Command1.Left = Command1.Left - Int((20 - 10 + 1) * Rnd + 10)


End If





IF ALL RIGTH THEN YOU MUST SEE THE NEXT CODE





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





e = Int((4 - 1 + 1) * Rnd + 1)





If e = 1 Then


Command1.Top = Command1.Top + Int((20 - 10 + 1) * Rnd + 10)


ElseIf e = 2 Then


Command1.Left = Command1.Left + Int((20 - 10 + 1) * Rnd + 10)


ElseIf e = 3 Then


Command1.Top = Command1.Top - Int((20 - 10 + 1) * Rnd + 10)


ElseIf e = 4 Then


Command1.Left = Command1.Left - Int((20 - 10 + 1) * Rnd + 10)


End If


End Sub


No comments:

Post a Comment