Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. mouse hover image

mouse hover image

Scheduled Pinned Locked Moved C#
csharpvisual-studioquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harcaype
    wrote on last edited by
    #1

    hi. How can you change the background image of a picture box when a mouse is hovered on it? I want it to change images as it hovers and leaves. My current image was set to the properties pane of visual studio 2005. How can you code the hover part?

    J 1 Reply Last reply
    0
    • H harcaype

      hi. How can you change the background image of a picture box when a mouse is hovered on it? I want it to change images as it hovers and leaves. My current image was set to the properties pane of visual studio 2005. How can you code the hover part?

      J Offline
      J Offline
      John_Adams
      wrote on last edited by
      #2

      Hi, Try the following code snippet: BEGIN CODE Public Class Form1 Dim image1 As String = Application.StartupPath + "\Water lilies.jpg" Dim image2 As String = Application.StartupPath + "\Winter.jpg" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub Private Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover Me.PictureBox1.BackgroundImage = Image.FromFile(image2) End Sub Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub End Class END CODE Hope this helps :).

      Regards, John Adams ComponentOne LLC

      H 1 Reply Last reply
      0
      • J John_Adams

        Hi, Try the following code snippet: BEGIN CODE Public Class Form1 Dim image1 As String = Application.StartupPath + "\Water lilies.jpg" Dim image2 As String = Application.StartupPath + "\Winter.jpg" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub Private Sub PictureBox1_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover Me.PictureBox1.BackgroundImage = Image.FromFile(image2) End Sub Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave Me.PictureBox1.BackgroundImage = Image.FromFile(image1) End Sub End Class END CODE Hope this helps :).

        Regards, John Adams ComponentOne LLC

        H Offline
        H Offline
        harcaype
        wrote on last edited by
        #3

        WOW THANKS! I just converted it into C# code. Thanks! :D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups