Results 1 to 32 of 32

Thread: Rollover Buttons

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Rollover Buttons

    Is it possible to make a rollover button using an image box, i know i have to use the mousemove sub but i dont know what code to use.

    I'll make this simple. 1st image is shown, when mouse goes over 2nd image is shown, when mouse leaves imagebox 1st image is shown

    thanks in advance
    chris1990
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  2. #2
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Rollover Buttons

    Chris,
    making a rollove is simple,
    load 2 images in to an imagelist control.

    on image mouse over, put
    Code:
    me.image1.picture=me.imagelist1.listimages(1).picture
    on form mouse over put
    Code:
    me.image1.picture=me.imagelist1.listimages(2).picture

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    theres only a mousemove mousedown and mouse up event, and this code makes the form flicker.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Rollover Buttons

    If your trying to make a rollover button why not use an actual button and just change the style property of the button to graphical. Then in the appropriate events change the picture property of the button.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    ive just tried it, is there a way to make the background of the button invisble like on labels.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  6. #6
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Rollover Buttons

    You referring to the border?

    Then no sorry
    Last edited by Paul M; Sep 28th, 2007 at 03:04 AM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    ye it has border round the image, can i remove it.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  8. #8
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Rollover Buttons

    Nope it would be best to use a PictureBox control and just edit the picture property like i said at the correct events.

  9. #9
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Rollover Buttons

    The flicker can occur in the Mouse_Move event becuase you are constantly trying to set the picture.. which takes up cpu...

    To overcome the flickering.. you can have a Boolean variable where Once your in the Mouse_Move event dont set the picture again constantly until the Boolean goes off when the mouse leaves the button.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    I believe this is what you are looking for
    vb Code:
    1. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. If (X < 0) Or (Y < 0) Or (X > Picture1.Width) Or (Y > Picture1.Height) Then
    3.        ReleaseCapture
    4.        'the mouse is no longer over the button, reload first image
    5.        Picture1.Picture = LoadPicture("c:\FirstImage.bmp")
    6. ElseIf GetCapture() <> Picture1.hwnd Then
    7.        SetCapture Picture1.hwnd
    8.        'the mouse is over the button, so load second image
    9.        Picture1.Picture = LoadPicture("c:\SecondImage.bmp")
    10. End If
    11. End Sub

  11. #11
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Rollover Buttons

    u can try using this control
    Attached Files Attached Files

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Quote Originally Posted by aashish_9601
    u can try using this control
    Did you create this control?

  13. #13
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: Rollover Buttons

    why so asked?
    are you feeling Something fishy

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Quote Originally Posted by aashish_9601
    why so asked?
    are you feeling Something fishy
    No....I'm just wondering if whatever your control does might be worth putting into our CodeBank to share with everyone.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    Hack, Please can you use different tags, when i copy and paste it goes in a straight line and dosent keep the format. Im at college at the moment, ill try it when i get home. thanks

    Im also gona look at the control that aashish_9601 has posted, thanks for that aswell
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  16. #16
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Quote Originally Posted by chris1990
    Hack, Please can you use different tags, when i copy and paste it goes in a straight line and dosent keep the format.
    Just click the quote button, and copy it from there.

    Don't actually submit the reply. Clicking quote will give you a straight text version.

    Also, if you are going to try aashish_9601's control, please let us know what you think of it.

    Thanks.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    Hack,

    I get sub not defined on your code for "ReleaseCapture" do i need to use an api call.

    aashish_9601's code works fine just needs touching up abit as the hoverbutton is smaller than the control, it could also do with a few instructions on how to change the picture and stuff.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  18. #18
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Oops...forgot to include the API declares. I will use the Code tags for these.
    Code:
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long 
    Private Declare Function ReleaseCapture Lib "user32" () As Long 
    Private Declare Function GetCapture Lib "user32" () As Long

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    Thanks,

    I now get the error "Method or data member not found"

    ElseIf GetCapture() <> Picture1.hwnd

    By the way im using an ImageBox not PictureBox if thats the problem.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  20. #20
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    You can't use an Image Box. It won't work. Image controls do not have an hWnd property. You have to use a picture control.

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    thanks it works, but can i make the background of the picturebox transparent like the imagebox because my button is slightly shaped. Also when the mouse leaves the hover button the form flashes.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  22. #22
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Quote Originally Posted by chris1990
    Also when the mouse leaves the hover button the form flashes.
    What? I've used that code in so many apps I can't even begin to remember and I've never had that kind of problem.

    Are these really large images you are working with?

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    Im using an image thats a tiny bit bigger than the start button on xp. Im trying to make my own customized replacement user interface that replaces the windows desktop.

    I dont think any code can be interfering because ive only just started and ive only done the graphics part and lining them up. Heres my code
    Code:
    Private Sub StartButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If (X < 0) Or (Y < 0) Or (X > StartButton.Width) Or (Y > StartButton.Height) Then
           ReleaseCapture
           'the mouse is no longer over the button, reload first image
           Me.Picture = RO_Buttons.ListImages(2).Picture
           StartButton.Picture = LoadPicture("C:\**\StartButton.gif")
    ElseIf GetCapture() <> StartButton.hwnd Then
           SetCapture StartButton.hwnd
           'the mouse is over the button, so load second image
           'Me.Picture = RO_Buttons.ListImages(1).Picture
           StartButton.Picture = LoadPicture("C:\Documents and Settings\**\StartButton_Light.gif")
    End If
    If StartMenu.Visible = True Then
    StartButton.Picture = LoadPicture("C:\Documents and Settings\****\Images\StartButton_Dark.gif")
    End If
    End Sub
    oh yeah i have a big background image, which is the part thats flashing.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  24. #24
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Quote Originally Posted by chris1990
    oh yeah i have a big background image, which is the part thats flashing.
    Well, I guess that is why it has never happened to me as I have never used a big background image.

    So, this background image covers the entire form, and all of the controls and such that are on the form are actually on this image, is that how it is set up?

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    The background image is in its own imagebox and the imagebox stops were the taskbar starts. Im not using the form picture control. Do you think that it wont stop, if not can i some how make the form transparent just so it shows the start menu and run another form on top for the desktop.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  26. #26
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Try using a picture box for that as well. The picture box is a bit more stable than the image control.

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    thanks, that seems to work

    Is it possible to strech an image in a picturebox and make the background transparent.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  28. #28
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    This is just a guess (in 14 years of VB work, I've never had any program specs tossed in my inbox requiring the use of graphic stuff. ), but, the picturebox does have an AutoSize property that is False by default.

    Change it to True and see what happens.

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    I've just fought of an idea.

    If i make the buttons and the rollover effect in flash will i be able to use them as buttons with the flash dll\ocx. I mean do they have the _click sub and do you think this will stop my form from flikering.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  30. #30
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    All buttons should have a click event that can be coded.

    As far as Flash is concerned, I would give it a shot and see how you like it.

  31. #31

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    Re: Rollover Buttons

    sorry it took so long, ive been a bit busy.

    I've made a flash button it does what i want but it has no click event do i code it whilst creating the button in flash.
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  32. #32
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rollover Buttons

    Quote Originally Posted by chris1990
    I've made a flash button it does what i want but it has no click event do i code it whilst creating the button in flash.
    I've never used a flash button (not even quite sure what it is), but if you can code it while creating it, then that is what I would do.

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