Results 1 to 3 of 3

Thread: How to change image when it click repeatedly

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2018

    How to change image when it click repeatedly

    I wont when I click the image it changes the image
    when I click the image again it well return to original image.
    I'm using this code but it changed one time.

    Private Sub Image1_Change()

    Image4.Picture = LoadPicture("C:\Users\pc1\Desktop\Projectsone\Untitled.jpg")

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Southern Tier NY

    Re: How to change image when it click repeatedly

    You'll need a value to use as a flag to indicate the state of the image, i.e. which image is showing.
    Typically this would be a Boolean value which can toggle between True and False, but you might want to use the Tag property of the control so you don't have to maintain a flag somewhere that is external to the control.

    The code might look like this.
    Private Sub Image1_Change()
      If Image4.Tag = "B" Then
        Image4.Tag = "A"
        Image4.Picture = LoadPicture("C:\Users\pc1\Desktop\Projectsone\Untitled.jpg")
        Image4.Tag = "B"
        Image4.Picture = LoadPicture("C:\Users\pc1\Desktop\Projectsone\Titled.jpg")
      End If
    End Sub
    Note that the code you posted didn't seem to correlate with what you said you needed, and my code was based on your code.
    The assumption being that when you click on something, you get an Image1_Change event, which is toggling the picture in Image4.
    If you really want to click on the image to toggle the image, change the event to the click event of the image control instead of the Changed event of a different image control.
    Last edited by passel; Feb 8th, 2018 at 06:43 AM.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    NC, USA

    Re: How to change image when it click repeatedly

    So, OP, what you are saying is you only have TWO images---an original, and another. Is that correct?

Tags for this Thread

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