image - 如何清除用户窗体中的图像?

标签 image excel controls userform vba

我有一个使用图像控件的用户窗体。我根据两个标准在此控件中显示图片。
当我想输入两个新条件时,我不知道如何在用户窗体中清除此图像。

最佳答案

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

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
在 MS Access 中使用的提示
请注意 MS Access 中重复 @DrMarbuse 的评论作为后期编辑的不同用途:

In Access 2010, the picture is directly set by the image path. So LoadPicture() shall not be used anymore (In Excel it is required). Everything stayed the same and worked like a charm.

关于image - 如何清除用户窗体中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47619363/

相关文章:

windows-phone-7 - 离线模式下带有自定义图层的 Windows Phone 7 map 控制

javascript - 如何在div中居中img

html - CSS 将图像和文本对齐在同一行

c# - OpenXML 电子表格获取列序号索引

excel - 将 ChChart 控件链接到电子表格控件数据

java - 如何在java中停止控制几秒钟?

javascript - 如何以增量分辨率下载图像?

java - 如何根据android/java/eclipse中textView中的文本更改imageView

excel - 如何使单元格范围在 VBA 中工作?

vba - 将新的 Excel 文档保存为无宏工作簿而不提示