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. Visual Basic
  4. Change the image on a button

Change the image on a button

Scheduled Pinned Locked Moved Visual Basic
designquestiondiscussionlearning
5 Posts 3 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.
  • R Offline
    R Offline
    rnamro
    wrote on last edited by
    #1

    :confused: Hello, I have an a button on a form, the button has an image set at design time. if certain conditions are met i would like to change the image on this button to a different image. both images in question are loaded as an application resource and appear as an image in the resources (My.resources.). I tried going the route of: if "condition met" then me.btnX.image = my.resources.image2 end if this does not work! any thoughts would be appreciated. Thanks!

    M T 2 Replies Last reply
    0
    • R rnamro

      :confused: Hello, I have an a button on a form, the button has an image set at design time. if certain conditions are met i would like to change the image on this button to a different image. both images in question are loaded as an application resource and appear as an image in the resources (My.resources.). I tried going the route of: if "condition met" then me.btnX.image = my.resources.image2 end if this does not work! any thoughts would be appreciated. Thanks!

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = WindowsApplication5.Properties.Resources.image2; } I have tried with BMP image. It works fine.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

      R 1 Reply Last reply
      0
      • M Michael Sync

        private void button1_Click(object sender, EventArgs e) { pictureBox1.Image = WindowsApplication5.Properties.Resources.image2; } I have tried with BMP image. It works fine.

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

        R Offline
        R Offline
        rnamro
        wrote on last edited by
        #3

        - The image is loaded into a button (not a picture box) - I am also coding in VB.Net VS2005, so to access the image in resources i refrence it as follows: My.Resources.ImageName The reference you listed: WindowsApplication5.Properties.Resources... is not in vs2005 Can any one help? -- modified at 16:42 Tuesday 21st August, 2007

        M 1 Reply Last reply
        0
        • R rnamro

          :confused: Hello, I have an a button on a form, the button has an image set at design time. if certain conditions are met i would like to change the image on this button to a different image. both images in question are loaded as an application resource and appear as an image in the resources (My.resources.). I tried going the route of: if "condition met" then me.btnX.image = my.resources.image2 end if this does not work! any thoughts would be appreciated. Thanks!

          T Offline
          T Offline
          TomGarth
          wrote on last edited by
          #4

          There is nothing wrong with your code. Try proving to yourself that "condition met" is actually True when it is tested, and that image2 is actually what you think that it is.

          Tom Garth Developer R. L. Nelson and Associates, Inc., Virginia

          1 Reply Last reply
          0
          • R rnamro

            - The image is loaded into a button (not a picture box) - I am also coding in VB.Net VS2005, so to access the image in resources i refrence it as follows: My.Resources.ImageName The reference you listed: WindowsApplication5.Properties.Resources... is not in vs2005 Can any one help? -- modified at 16:42 Tuesday 21st August, 2007

            M Offline
            M Offline
            Michael Sync
            wrote on last edited by
            #5

            rnamro wrote:

            The reference you listed: WindowsApplication5.Properties.Resources... is not in vs2005

            I'm using VS 2005 and C# as language."WindowsApplication5" is the project name. button1.BackgroundImage = WindowsApplication5.Properties.Resources.logo ; Okay. I will give you the VB.NET 2005 code. Please try the following steps. - Create the new VB.NET window application in Visual Studio 2005 In Solution Explorer ~ 1. Go to My Project under project root. 2. Double click to open the properties. 3. Go to "Resources" 4. Click "Add Resource" and "Add existing file" 5. ("File Open" dialog will be opened) Select the picture. 6. then, Save 7. Go to button Click event. (Make button a lit bit larger to see the image.) 8. Write the code below Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.BackgroundImage = My.Resources.Image1 End Sub 9. Run the application 10. Click the button (Observe: the image will be shown on the button) Hope it helps.

            Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

            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