dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    11

    How to change image when it click repeatedly

    HELLO
    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
    Location
    Southern Tier NY
    Posts
    4,410

    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.
    Code:
    Private Sub Image1_Change()
    
      If Image4.Tag = "B" Then
        Image4.Tag = "A"
        Image4.Picture = LoadPicture("C:\Users\pc1\Desktop\Projectsone\Untitled.jpg")
      Else
        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 05:43 AM.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,418

    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
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.