VBA:单击元素后无法更改图像控件图片 [英] VBA: Can't change Image Control picture after click on element

查看:115
本文介绍了VBA:单击元素后无法更改图像控件图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置

我有一个带有图像控件元素的Excel VBA UserForm.单击表单中的按钮时,将使用以下代码设置/更新图像控件的Picture源:

I have an Excel VBA UserForm with an Image Control element. When clicking on buttons in the form, the Image Control's Picture source is set / updated with the following code:

Set MyForm.imgControl.Picture = LoadPicture(pathToFile)

问题

当用户单击图像控件时,不再更新其Picture源.无论何时在工作流中单击图像控件",都会出现此问题:

When the user clicks on the Image Control, updating its Picture source doesn't work anymore. The problem occurs, no matter when in the workflow the Image Control is clicked:

  • 示例1:用户单击一个按钮来设置图片(图片正确设置).用户单击图像控件.用户单击其他按钮来更改图片->显示的图片不变.
  • 示例2:用户在加载表单后立即单击Image Control.用户单击按钮更改图片->显示的图片不变.

如果用户从不单击图像控件,则所有操作均会顺利进行.值得注意的是,单击图像控件"并没有明显地将其聚焦.

If the user never clicks on the Image Control, everything works perfectly smoothly. It's worth noting that clicking on the Image Control doesn't visibly focus it.

问题

单击图像控件不会影响图片是否可以更新.如何才能做到这一点?或者,至少,有人知道为什么发生了解释的行为,还是仅仅是一个错误?

Clicking on the Image Control shouldn't make a difference in whether or not the Picture can be updated or not. How can this be done? Or, at least, does anyone know why the explained behavior is happening, or is it just a bug?

该控件确实具有Click/MouseDown/...事件(为空),但没有采用Cancel参数.

The Control does have Click / MouseDown / ... events (which are empty), but they don't take a Cancel parameter.

推荐答案

正如您所说,它听起来确实像个错误,但是作为一种变通办法,我建议在更改图片后强制重新粉刷:

It does sound like a bug, as you say, but as a workaround, I'd suggest forcing a repaint after changing the picture:

Set MyForm.imgControl.Picture = LoadPicture(pathToFile)
MyForm.Repaint

这篇关于VBA:单击元素后无法更改图像控件图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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