鼠标事件定时 [英] Mouse down event timing
问题描述
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屋!