问题
I have a Userform in which I use an Image field. I display a picture in this field, based on two criteria. I don't know how to clear this Image in the Userform when I want to type two new criteria.
回答1:
You can easily 'clear' your UserForm Image control (e.g. Image1) via Image1.Picture = LoadPicture(vbNullString)
. In the example below you would switch between showing a defined picture and displaying the empty control when clicking your command button. In order to control the Image status (empty or not) you check the image picture property via If Image1.Picture Is Nothing Then
...
Code example in userform module
Option Explicit
Private Sub CommandButton1_Click()
' Purpose: Change view between given image and no image
Dim sImgName As String ' picture name string
sImgName = "C:\Temp\MyPicture.gif"" ' <<< choose your picture name"
With Me.Image1
If .Picture Is Nothing Then ' picture property has been cleared already
.Picture = LoadPicture(sImgName)
Else ' a picture is already displayed
.Picture = LoadPicture(vbNullString) ' clear it now
End If
End With
End Sub
来源:https://stackoverflow.com/questions/47619363/how-to-clear-an-image-in-a-userform