当鼠标悬停在其上时如何在Excel用户窗体中显示包含图像的弹出窗口

问题描述:

请考虑以下内容:
我有一个excel用户窗体,其中包含已减小尺寸的图像对象.当用户将鼠标悬停在图像上时,我希望该图像弹出并以原始大小显示相同的图像.

其工作方式的一个示例是在 ControlTipText 中添加文本,然后当光标悬停在图像上时,它会显示文本,但是我希望它显示文本而不是文本.

Consider the following:
I have an excel userform that contains image objects that have been reduced in size. When the user hovers on an image, I would like the image to popup and display the same image but in its original size.

An example of how it would work is by adding text to ControlTipText and when the cursor is hovering the image, it would display the text, but instead of text, I would like it to display the image.

外观如何

用户窗体:

当光标悬停在图像上时:

When cursor hovers on the image:

我尝试了以下操作:
使用 MouseMove 函数,当光标在图像上时,它将显示该图像的放大版本的另一种用户形式.
我还尝试使用计时器在几秒钟后关闭用户表单.

I've tried the following:
Using the MouseMove function, when cursor is on the image, it would display another userform of the enlarged version of that image.
I've also tried using a timer to close the userform after a few seconds.

这两种方法都不友好,因为用户必须自己关闭用户窗体或等待用户窗体自动关闭.

Both methods are not user-friendly as the user would have to close the userform themselves or wait for the userform to close automatically.

您可以在鼠标悬停在缩略图上时调整主用户窗体的大小,以便显示更大的图像.从这样布置的用户表单开始:

You could resize the main UserForm on mouse-over of a thumbnail so that it reveals a larger image. Start with a user form laid out like this:

在使用前,请调整用户窗体的大小,以使其隐藏大图像.

缩略图适合 width = 100 ,而完整格式为 width = 340 .

The thumbnails fit within width = 100, whilst the full form is width = 340.

向用户窗体添加如下所示的子项:

Add subs like the following to the UserForm:

Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    UpdateLargeImage UserForm1.Image1.Picture
End Sub
Private Sub Image2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    UpdateLargeImage UserForm1.Image2.Picture
End Sub
Private Sub UpdateLargeImage(ByVal Image As Object)
    UserForm1.Width = 340
    UserForm1.Image3.Picture = Image
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    UserForm1.Width = 100
End Sub

您可以看到两个调整大小的命令,具体取决于鼠标的移动方向,并且还有一个通用的 UpdateLargeImage 子菜单,该子菜单可以显示较大的图像并将其设置为缩略图中的任何图像.

You can see the two resizing commands depending what the mouse is moving over, and also that there is a generic sub UpdateLargeImage which reveals the larger image and sets it to whatever image was in the thumbnail.

测试: