如何清除用户表单中的图像? [英] How to clear an Image in a Userform?

查看:111
本文介绍了如何清除用户表单中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用图像字段的用户窗体。我基于两个条件在此字段中显示图片。当我要输入两个新条件时,我不知道如何在用户窗体中清除该图像。

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.

推荐答案

通过 Image1.Picture = LoadPicture(vbNullString) 'clear'您的UserForm图像控件(例如Image1)。在下面的示例中,您将在显示定义的图片和单击命令按钮时显示空白控件之间切换。为了控制图像状态(是否为空),您可以通过如果Image1.Picture Nothing那么 ...

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...

用户窗体模块中的代码示例

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

这篇关于如何清除用户表单中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆