Code to SpeedUp MouseOver Effect

时间:2017-01-12 11:16:22

标签: excel-vba vba excel

以下是我的代码:

Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If X < 1 Or X > Label1.Width - 1 Or Y < 1 Or Y > Label1.Height - 1 Then
   ActiveSheet.Shapes.Range(Array("Menu2")).Visible = msoFalse
   Else
   ActiveSheet.Shapes.Range(Array("Menu2")).Visible = msoTrue
End If

End Sub

此代码显示名为Menu2的形状。我面临一个问题,当我以速度移动鼠标时,Menu2的形状仍然存在。有没有办法加快速度?

感谢。 萨勒曼

1 个答案:

答案 0 :(得分:0)

不幸的是,public class SomeType { public int Id { get; set; } public SomeTypeType Type { get; set; } public DateTime Time { get; set; } public T Object { get; set; } } public class SomeType<T> : SomeType { public T Object { get; set; } public SomeType() { } public SomeType(SomeType someType, T obj) { this.Id = someType.Id; ... this.Object = obj; } } var someType = _connection.Query<SomeType>("SELECT Id, Type, Time FROM table"); var obj = new Foo(); var specialisedSomeType = new SomeType<Foo>(someType, obj); 事件仅在控件周围的几个像素内触发(我得到的X和Y最低为-3.75)。我能想到的最简单的选择是在它后面制作一个大的透明标签并使用它的MouseMove事件。第二个标签的初始属性设置:

MouseMove

然后(Label2.BackStyle = fmBackStyleTransparent Label2.Visible = False Label2.Caption = "" 是控件所在的工作表):

Me

另一种方法是使用Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Me.Shapes("Menu2").Visible = True Me.Label2.Visible = True ' optional so the Label2_MouseMove event triggers Me.Application.Cursor = xlNorthwestArrow ' optional to avoid the xlWait cursor flickering End Sub Private Sub Label2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Me.Shapes("Menu2").Visible = False Me.Label2.Visible = False ' optional so the Label2_MouseMove event doesn't trigger after the first time Me.Application.Cursor = xlDefault ' optional to restore the cursor End Sub WinAPI - MouseMove - What is the reverse event?