Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Making a button move on mouseover

jerrysljerrysl Posts: 3Member
There's a button in my program that I want to move when the mouse goes near it (a pixel before it touches it). I can't find a cmdBlah_mouseover. Does VB6 not have one? I can't seem to find an alternative. I don't want the button to go off the form but to the other side like a snake game I guess.

Comments

  • leeosleeos Posts: 1,212Member
    : There's a button in my program that I want to move when the mouse goes near it (a pixel before it touches it). I can't find a cmdBlah_mouseover. Does VB6 not have one? I can't seem to find an alternative. I don't want the button to go off the form but to the other side like a snake game I guess.

    i think you'll find its there.


  • jerrysljerrysl Posts: 3Member
    actually, i found this

    http://www.vb-helper.com/howto_annoying_game.html

    it's funny. but the question remains: how do you make it move away in the direction the mouse is moving? so you can kind of push it around.
  • infidelinfidel Posts: 2,900Member
    : actually, i found this
    :
    : http://www.vb-helper.com/howto_annoying_game.html
    :
    : it's funny. but the question remains: how do you make it move away in the direction the mouse is moving? so you can kind of push it around.

    You can't really use the button's mouse events because you stated you want the program to react before the mouse gets to the button. That means you'll not only have to have the form itself track the mouse position, but it's relative movement so you know which direction the mouse is moving.

    Try this:
    [code]
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Debug.Print X & " " & Y

    End Sub
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • jerrysljerrysl Posts: 3Member
    well i guess i misled myself when i said i wanted the button to move when the mouse comes within a certain area. the code i found works just fine for me. but i can't figure out how to make it move in the direction the mouse "pushes" it.
  • infidelinfidel Posts: 2,900Member
    : well i guess i misled myself when i said i wanted the button to move when the mouse comes within a certain area. the code i found works just fine for me. but i can't figure out how to make it move in the direction the mouse "pushes" it.

    For that you'll have to track the mouse movement and use some algorithm to determine the direction. Something like this:

    [code]
    Option Explicit

    Dim X1 As Single
    Dim Y1 As Single
    Dim pushing As Boolean

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

    pushing = True

    End Sub

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

    Dim dX As Single
    Dim dY As Single

    dX = X - X1
    dY = Y - Y1

    If pushing Then
    With Me.Command1
    .Move .Left + dX, .Top + dY
    End With
    End If

    X1 = X
    Y1 = Y

    End Sub

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

    pushing = False

    End Sub
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.