问题
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.
How it would look like
The userform:
When cursor hovers on the image:
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.
回答1:
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:
Before use, resize the UserForm so that it hides the large image.
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
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.
Test:
来源:https://stackoverflow.com/questions/45073072/how-to-display-a-popup-containing-an-image-in-excel-userform-when-mouse-is-hover