如何获取鼠标是否进入控件(按钮tips显示)?

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2017-03-06 14:26:14

  答:现用commandbutton控件举例,其他控件一样:
1.首先声明两个API函数
//获得焦点
Function ulong SetCapture(ulong hWnd) Library "USER32.DLL"
//释放焦点
Function BOOLEAN ReleaseCapture() Library "USER32.DLL"

2.自定义用户事件鼠标在控件上移动mousemove(EventID号为pbm_mousemove),鼠标进入控件mousewithin,鼠标离开控件mousewithout。

3.声明一些Instance变量
boolean ib_mousecaptured//控件是否已经获得焦点
boolean ib_mousewithin//鼠标是否进入控件
integer ii_losecapture=0//控件是否要失去焦点

4.在mousemove事件中写入
if ii_losecapture > 1 then
if not ib_mousecaptured then//没有捕获鼠标移动
//捕获鼠标移动
SetCapture(handle(this))
ib_mousecaptured = TRUE
else //已经捕获鼠标移动
if xpos < 0 or ypos < 0 or xpos > width or ypos > height then//鼠标不在该控件上
//释放鼠标
ReleaseCapture()
ib_mousecaptured = FALSE
//触发mousewithout事件
this.post event mousewithout()
ib_mousewithin=false
ii_losecapture=0
//this.of_set()
else
if not ib_mousewithin then
//触发mousewithin事件
this.post event mousewithin()
ib_mousewithin=true
end if
end if
end if
else
ii_losecapture=ii_losecapture + 1
end if

5.最后你就可以在mousewithin和mousewithout中写入你想要的效果或事件。

of_set()可能是重置某些值的操作,可以不用它,将它注释掉,一样可以实现诸如鼠标到达按钮时显示tips。


Tags:

作者:佚名
分享到: 微信 更多