Thread: [Solved] change the image by clicking
View Single Post
 
Old 03-23-2019, 03:23 AM
matapagi2019 matapagi2019 is offline Windows XP Office 2007
Novice
 
Join Date: Mar 2019
Posts: 12
matapagi2019 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You cannot get the image name that way, so you need to set a value that you can read from the command button whenever the image changes. You could use a hidden check box or a hidden label or use the tag property of the userform e.g.
Code:
Private Sub UserForm_Initialize()
    Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
    Label2.Caption = "Image1"
    Label2.Visible = False
    'Tag = "Image1"
End Sub

Private Sub CommandButton1_Click()
    If Label2.Caption = "Image1" Then
        'If Tag = "Image1" Then
        Label1.Picture = LoadPicture("D:\My Pictures\Image_2.bmp")
        Label2.Caption = "Image2"
        'Tag = "Image2"
    Else
        Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
        Label2.Caption = "Image1"
        'Tag = "Image1"
    End If
End Sub
From your explanation, it makes perfect sense to me.
And I'm sure it will work well.
So, thank you very much for your help.
And I think the problem has been solved.

regards.
Reply With Quote