vba 在 vb6 中在图像上热制作鼠标离开事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3423022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:58:15  来源:igfitidea点击:

Hot make a mouse leave event in vb6 over a image

vbavb6mouseleave

提问by PUG

I have a image for which i have written code in MouseMove to higlight it. this is being done what i want is to when the mouse leaves image the highlights go away but i cant seem to find any event which will do that. i am working in visual basic 6.0. i have tried the mouseup and down event but they dont match my req.

我有一个图像,我在 MouseMove 中为其编写了代码以突出显示它。这是我想要的,当鼠标离开图像时,高光消失,但我似乎找不到任何可以做到这一点的事件。我在 Visual Basic 6.0 中工作。我已经尝试过 mouseup 和 down 事件,但它们不符合我的要求。

Thanks

谢谢

回答by MarkJ

There isn't an event like that in VB6 (although VB.Net has MouseLeave). You will need to do something in the MouseMove event of the form (and perhaps any container controls too).

在 VB6 中没有这样的事件(尽管 VB.Net 有MouseLeave)。您需要在窗体的 MouseMove 事件中做一些事情(也许还有任何容器控件)。

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ' Unhighlight the image'
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ' Highlight the image'
End Sub

回答by Shane Miskin

There is a great little ocx control for this exact purpose written by Marco Bellinaso, a well respected author and a big contributor of good content to the VB community in his time.

Marco Bellinaso 是一位受人尊敬的作者,同时也是 VB 社区优秀内容的重要贡献者,为此专门编写了一个很棒的 ocx 控件。

The control is called the "MB MouseHelper". You can download it from devx.com at http://www.devx.com/vb2themax/CodeDownload/19735.

该控件称为“MB MouseHelper”。您可以从http://www.devx.com/vb2themax/CodeDownload/19735从 devx.com 下载它。

alt text http://img25.imageshack.us/img25/3985/screencap20100809110523.jpg

替代文字 http://img25.imageshack.us/img25/3985/screencap20100809110523.jpg

There are two problems with using VB's built in MouseMoveevent that make this control useful:

使用 VB 的内置MouseMove事件使此控件有用有两个问题:

  • You have to catch all the places where the user could put the mouse when it leaves your image, like the form or another control or a nearby label
  • And the user can still move the mouse very quickly, jumping over any part of the window that would trigger the MouseMoveevent that unhighlights your image
  • 您必须捕获用户在鼠标离开图像时可以放置鼠标的所有位置,例如表单或其他控件或附近的标签
  • 并且用户仍然可以非常快速地移动鼠标,跳过会触发MouseMove取消突出显示图像的事件的窗口的任何部分

回答by Claudio

You can also put the image you want to simulate the mouseleave event inside a bigger picture. That way, when you leave the inner picture (smaller) you will hit the mousemove event of the outer picture. Also, this works if you use a frame or label instead of another picture

您还可以将要模拟 mouseleave 事件的图像放在更大的图片中。这样,当您离开内部图片(较小)时,您将点击外部图片的 mousemove 事件。此外,如果您使用框架或标签而不是另一张图片,这也有效

回答by Paul Michaels

You can always subclass the control. Here's an articlethat describes how to do it.

您始终可以对控件进行子类化。 这是一篇描述如何做到这一点的文章

回答by Dia

One thing to care about if you use the mouseMove event is to raise a flag when you are IN the control you want to highlight and raise another when you are OUT so as not to repeat the same action on each mouse xy change

如果您使用 mouseMove 事件,需要注意的一件事是在您要突出显示的控件中时引发一个标志,并在您退出时引发另一个标志,以免在每次鼠标 xy 更改时重复相同的操作

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ' if imageIsHighlighted = true then
  '    Unhighlight the image'
  '    imageIsHighlighted = false
  ' end if 
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ' if imageIsHighlighted = false then
  '       Highlight the image'
  '       imageIsHighlighted = True
  ' end if 
End Sub