鼠标事件定时 [英] Mouse down event timing

查看:315
本文介绍了鼠标事件定时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求编写在Excel中单击图像的功能,并在其上添加一个形状(它是物理治疗师的身体图,形状将指示患者疼痛的位置)。我的代码通过使用ActiveX图像控件的鼠标向下事件来做到这一点:

  Private Sub bodypic_MouseDown(ByVal Button As Integer, _ 
ByVal Shift As Integer,ByVal x As Single,ByVal y As Single)

ClickShape x,y

End Sub






  Sub ClickShape(x As Single,y As单个)

Dim shp As Shape
Dim cursor As Point

Set shp = ActiveSheet.Shapes.AddShape(msoShapeMathMultiply,x + ActiveSheet.Shapes(bodypic ).Left,_
y + ActiveSheet.Shapes(bodypic)。顶部,26,26)

用shp.Fill

.ForeColor.RGB = RGB(255,0,0)
.BackColor.RGB = RGB(255,0,0)

结束

shp.Line.Visible = False

End Sub

问题是当鼠标光标在图形不可见。只有当鼠标离开图表时,才会出现形状。



我尝试过各种方法刷新屏幕,选择单元格,甚至通过 Lib User32中的SetCursor方法。除了用户实际移动鼠标之外,没有什么可以工作。



要重新创建问题:插入一个大约200 x 500像素的ActiveX图像控件,将一个jpeg图像添加到控制,将鼠标向下的代码添加到工作表中,并将单击形状代码添加到模块中。

解决方案

这是非常黑客,但是发现隐藏和取消隐藏图像解决了问题:

  ActiveSheet.Shapes(bodypic)。Visible = False 
ActiveSheet.Shapes(bodypic)。Visible = True
End Sub

d欢迎更多优雅的答案!


I've been asked to code the ability to click on an image in Excel and add a shape on top of it (it's a body diagram for a physiotherapist, the shape will indicate the site of the patient's pain). My code does this OK by using the mouse down event of an ActiveX image control:

Private Sub bodypic_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)

ClickShape x, y

End Sub


Sub ClickShape(x As Single, y As Single)

Dim shp As Shape
Dim cursor As Point

Set shp = ActiveSheet.Shapes.AddShape(msoShapeMathMultiply, x + ActiveSheet.Shapes("bodypic").Left, _
y + ActiveSheet.Shapes("bodypic").Top, 26, 26)

With shp.Fill

    .ForeColor.RGB = RGB(255, 0, 0)
    .BackColor.RGB = RGB(255, 0, 0)

End With

shp.Line.Visible = False

End Sub

The problem is that while the mouse cursor is over the diagram the shape is not visible. Only when the mouse is moved off of the diagram does the shape appear.

I've tried various methods to refresh the screen, selecting a cell, even changing the cursor position via the SetCursor method in Lib user32. Nothing seems to work except for the user actually moving the mouse.

To recreate the issue: insert an ActiveX image control roughly 200 x 500 px, add a jpeg image to the control, add the mouse down code to the worksheet and the click shape code to a module.

解决方案

This is very hacky but I discovered that hiding and unhiding the image solves the problem:

ActiveSheet.Shapes("bodypic").Visible = False
ActiveSheet.Shapes("bodypic").Visible = True
End Sub

I'd welcome more elegant answers!

这篇关于鼠标事件定时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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