Results 1 to 12 of 12

Thread: rollover image...please helppp!!!!

  1. #1

    Thread Starter
    Hyperactive Member dflw's Avatar
    Join Date
    Apr 2001
    Location
    ct, usa
    Posts
    412

    rollover image...please helppp!!!!

    hello,

    how do i make an image change to another image on top of it when the mouse moves over it???

    thanks in advance
    Visual Basic 6, HTML, JavaScript, learning C++

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I know how to do it... so long as it's a picturebox, and not an imagebox. I'll post that in a couple of minutes.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3
    Junior Member
    Join Date
    Mar 2001
    Location
    Houston
    Posts
    31
    You can use the imageList control to store your various images.

    When firing the mouseover event , just change the .picture property of you image/picture control


    THeNU

  4. #4
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    Test to see if the cursor is over the image and when it is out.
    Code:
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        
        
        Picture1 = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Bitmaps\Assorted\beany.bmp")
    End Sub

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Thenu, jjortiz. Your method, I guess, would not "provide" the desired rollover image function. Since the image would not change back when the mouse is not over the image anymore. You need to use the SetCapture and ReleaseCapture to acheive this. Give a couple of minutes.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Here it is

    Hope this helps:

    Code:
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        With Picture1
            If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
                ReleaseCapture
                .Picture = RollOver(0).Picture
            Else
                SetCapture .hwnd
                .Picture = RollOver(1).Picture
            End If
        End With
        
    End Sub
    The PictureBox RollOver is an array, but you can use whateve method you like to load one or other image. You can also get it from an imagelist or load it directly from the hard disk (with the loadpicture)
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7
    Junior Member
    Join Date
    Mar 2001
    Location
    Houston
    Posts
    31
    Mc Brain

    What you can do is to detect when the mouse leave the image/picture control, by i.e. checking the mouseover event of the surrounding controls (probably just the form or a frame).

    picture.mouseover
    change picture to #1

    form.mouseover
    change picture back to #0

    thenu

  8. #8
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301
    For detecting when the mouse is out of the picture box, allocate it in a frame and then use the mouse-over event of the frame to restore the original image.
    Combat poverty: kill a poor!!

  9. #9
    Frenzied Member jjortiz's Avatar
    Join Date
    Mar 2001
    Location
    NYC
    Posts
    1,768
    Mc Brain. In my post i explain that you have to check to see if the cursor is in the picturebox or out. I guess that i could have written the entire code. That would have been too easy.

  10. #10
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    For detecting when the mouse is out of the picture box, allocate it in a frame and then use the mouse-over event of the frame to restore the original image.
    I don't like this solution since it would only work when you try your program. I can assure you, that the final user won't move the mouse slowly so that the image is loaded back. Not because they're evil, just because they are not suppose to know that the image will change back when the move the mouse over the frame. I guess that mine is the best solution for this stuff.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I agree with McBrain. SetCapture and ReleaseCapture is the way to go.
    However you need to make a call to SetCapture in the MouseUp event of the PictureBox also otherwise it wont work proparly if you click on the PictureBox.

    Cheers,

  12. #12
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I've never thought of the clicking event...
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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