Results 1 to 16 of 16

Thread: Rollover buttons

  1. #1

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Rollover buttons

    Hi,

    Does anyone know how to make rollover images in vb.net?

    I have been searching for code for ages and unable to find any!

    Thanks, Andy
    Living a Lie, Timmy

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Rollover buttons

    Use the MouseEnter and MouseLeave events. When your mouse enters change your buttons image to a different one. Then in the Mouse leave event replace the image with the origional one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Rollover buttons

    Where can I find these events?

    I am really new to vb.net!

    thanks, Andy
    Living a Lie, Timmy

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Rollover buttons

    Add a Button on to your form. Switch to the code behind view and from the top left combo box choose youur new button from the list. Then click on the combo box on the top right side and select MouseEnter. Upon that click you will be taken to a newly created event procedure for the button called Button1_MouseEnter.

    Do the sme for MouseLeave. Then place your code in each for changing the image to your desired one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Rollover buttons

    Just find it in your events list at the top, in the comboboxes. Choose your button, then the list shows up on the right, as the pic shows below
    Attached Images Attached Images  

  6. #6

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Rollover buttons

    Sorry guys, I must appear stupid. I created a new button called "button1", then I changed the image in the properties to a jpeg and then changed the event to mouseenter in the code view.

    I am stuck here now as i'm not sure where the new (hover over) image is stored?
    Living a Lie, Timmy

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Rollover buttons

    You can add it from a file on your filesystem or use a ImageList control to contain the needed images that you would add to it for use throughout your app.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Rollover buttons

    you have to set the image in the event... like MouseEnter, have code to set the image property... like...
    VB Code:
    1. Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
    2.         Button1.Image = Image.FromFile("c:\test.jpg")
    3.     End Sub
    4.  
    5.     Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    6.         Button1.Image = Nothing
    7.     End Sub
    Of course, you dont have to load it from file every time like the code above, you can load the image, say, on form load, and store it in an image object and just access the image object, just used that above as a sample...
    Last edited by gigemboy; Jan 24th, 2006 at 02:11 PM.

  9. #9
    Addicted Member
    Join Date
    Dec 2005
    Posts
    198

    Re: Rollover buttons

    This may help you, it's a class i made, you need to set up five images, one the mask image (it need to be black), other four images are to represent different button states (normal, pressed, over and disabled). I hope you find it useful.
    Regards!.
    Attached Files Attached Files

  10. #10

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Rollover buttons

    Quote Originally Posted by gigemboy
    you have to set the image in the event... like MouseEnter, have code to set the image property... like...
    VB Code:
    1. Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
    2.         Button1.Image = Image.FromFile("c:\test.jpg")
    3.     End Sub
    4.  
    5.     Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    6.         Button1.Image = Nothing
    7.     End Sub
    Of course, you dont have to load it from file every time like the code above, you can load the image, say, on form load, and store it in an image object and just access the image object, just used that above as a sample...

    Thanks for that code it was helpful!

    Is there anyway of doing it with a picture box instead as I am having troubles doing it?

    Here is the code I am using

    --------------------------------------------------------------
    Private Sub PictureBox1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    PictureBox1.Image = Image.FromFile("C:\Documents and Settings\Andy\My Documents\Uni Work\Year 3\PRMM301\program\vb\eJukebox_New\images\forward_button.jpg")
    End Sub

    Private Sub PictureBox1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    PictureBox1.Image = Nothing
    End Sub
    ---------------------------------------------------------------------

    Thanks, Andy
    Living a Lie, Timmy

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Rollover buttons

    I would suggest creating an ImageList and assigning that to the ImageList property of your Button. Then in the event handlers you can simply set the ImageIndex property. A value of -1 would mean no image.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Rollover buttons

    Note that when you call Image.FromFile the file remains locked until you Dispose the Image. You care not doing that so the second, and every subsequent, call to FromFile will not work. Having said that, you don't want to create a new Image from a file each time anyway as it's very time consuming. You can have a class-level variable of type Image. In the MouseEnter event handler you would test that variable and if it is Nothing you would create an Image object and assign it to the variable. Then you assign that variable to the PictureBox's Image property. This way you only create a single Image object so it is more efficient and you'll have no issues with the file being locked because you'll only be accessing it once. You might also want to look into embedding your image(s) as a resource.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265

    Re: Rollover buttons

    I notice that somehow you've got both your events are handling the click events and not MouseEnter and MouseLeave. You'll need to change that before they'll work properly

    VB Code:
    1. Private Sub TextBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseEnter
    2.  
    3.         PictureBox1.Image = Image.FromFile("C:\Documents and Settings\Andy\My Documents\Uni Work\Year 3\PRMM301\program\vb\eJukebox_New\images\forward_button.jpg")
    4.  
    5.     End Sub
    6.  
    7.     Private Sub TextBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
    8.  
    9.          PictureBox1.Image = Nothing
    10.  
    11.     End Sub
    Nick.

  14. #14

    Thread Starter
    Addicted Member sotusotusotu's Avatar
    Join Date
    Aug 2001
    Location
    Plymouth, England
    Posts
    158

    Re: Rollover buttons

    Thanks guys!

    Big help!
    Living a Lie, Timmy

  15. #15
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: Rollover buttons

    would it be possible to have a rollover on listview item??? When the mouse is over a item in the list view it shows information like tooltip... would that be possible??
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Rollover buttons

    Quote Originally Posted by jcavard
    would it be possible to have a rollover on listview item??? When the mouse is over a item in the list view it shows information like tooltip... would that be possible??
    Quite different question. Should be asked in a new thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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