如何清除用户表单中的图像?

Chi*_*mos 1 excel controls vba image userform

我有一个用户表单,我在其中使用了一个图像字段。我根据两个标准在此字段中显示图片。当我想输入两个新条件时,我不知道如何在用户表单中清除此图像。

T.M*_*.M. 8

您可以轻松地“清除”通过您的用户窗体图像控制(例如图像1) Image1.Picture = LoadPicture(vbNullString)。在下面的示例中,您将在单击命令按钮时在显示定义的图片和显示空控件之间切换。为了控制图像状态(是否为空),您可以通过If Image1.Picture Is Nothing Then...检查图像图片属性

用户表单模块中的代码示例

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
Run Code Online (Sandbox Code Playgroud)