How to clear an Image in a Userform?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 07:05:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!