动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   程序开发 → 阅读文章

 如何获取鼠标是否进入控件

作者来源: 
阅读 数 78 人次 , 2006-4-26 11:18:00 

现用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。

  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:在PB中实现串口编程
· 下一篇:如何实现HTML格式帮助文件的相关调用
· 需求源于沟通 获取需求十大沟通技巧
· COM在WinCE串口通信中的应用
· 用预测性对象点度量面向对象软件(1)
· NoahWeb™引擎介绍
· 统一建模语言UML释义(二)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077