CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    10

    Mouse and an image?

    I have two images: imgSaveUp and imgSaveDown ( it acks like a button )
    defaults: imgSaveUp.Visible =True
    imgSaveDown.Visible= False

    And in
    Private Sub imgSaveUp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    imgSaveUp.Visible = True
    imgSaveDown.Visible = False
    End Sub

    Private Sub imgSaveUp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    imgSaveUp.Visible = False
    imgSaveDown.Visible = True
    End Sub

    So that pressing on the imgSaveUp causes to look like a button is pressed. What I would like to do is also use the mouse that when it is over the button it makes it look like its been pressed but when the mouse is off the button it goes back to its normal state. I know there is a MouseMove event but i need to know I guess were the mouse is and if its on top of the image.

    Any ideas on how to accomplish this?

    Thanks


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Mouse and an image?

    could you try this?

    private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    print "ButtoN: " & X
    End Sub

    private Sub Form_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    print "form: " & X
    End Sub



    whenever the mouse is over the button the button's MOusemove event is triggered. If it's off the button the form's mousemove is triggered...


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Mouse and an image?

    Mousemove occurs only when the cursor is OVER the control. So it is more easy to detect WHEN the mouse is entering your control area, and when it is inside it. But to detect when it left your control, there are 2 methods.

    One is ( As Suggested by Lother): Have the form do that job. This would be more easy ( clean & simple) in the case of: one Form with few controls on it.

    Other is to Use SetCapture, to create your won "MouseLeave" event: When SetCapture mouse move events are sent to your Control even when cursor is outside the control boundaries. Then check the position, and release the capture when outside, and change the image from down to up.
    This procedure has its own troubles with VB to handle 'Clicks', as VB internally sets the capture to handle clicks.

    In your case, you need to pole for both images.
    I would change it to one: Have 3 images!!: Only one Visible and other two just as holders for images, and use another variable to hold the state. then i need to code for only (one) visible image control.
    On MouseDown Change the Picture of this to "Down" picture and on MouseUp change to "Up" picture.
    That would also avoid (possible) flicker!.

    Ravi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured