computer 版 (精华区)
发信人: windoe (为中国电信做贡献), 信区: program
标 题: VB:怎么在VB中实现Delphi那样的MouseEnter和MouseExi
发信站: 听涛站 (Fri Mar 10 19:09:11 2000), 转信
VB中的鼠标事件驱动只有MouseDown,MouseMove,MouseUp三个事件,没有象
Delphi那样提供MouseEnter(OnEnter)和MouseExit(OnExit)的事件。而这两个事件是平
时编编写程序经常要用到的,我们可以通过调用SetCapture和ReleaseCapture这两个Wi
ndows API函数的方法来实现它。具体步骤如下?
1) 在VB中新建一个标准EXE工程;
2) 画出一个按钮Command1;
3) 在窗体Form1中定义Windows API的声明;
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Lon
g
Private Declare Function ReleaseCapture Lib "user32" () As Long
4) 在Command1的MouseMove事件中编写以下代码:
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Sin
gle,, Y As Single)
Dim MouseEnter As Boolean '鼠标进入的标志位
MouseEnter = (0 <= X) And (X <= Command1.Width) And (0 <= Y) And (Y <= Comma
and1.Height) '计算鼠标的移动是否在Command1里面
If MouseEnter Then '鼠标已经进入
Me.Caption = "Mouse In Button!"
SetCapture Command1.hWnd
Else '鼠标已经离开
Me.Caption = "Mouse Out!"
ReleaseCapture
End If
End Sub
--By Kammi's SuperPost General Version
--
夜中不能寐,起坐弹鸣琴。
薄帷鉴明月,清风吹我襟。
孤鸿号外野,翔鸟鸣北林。
徘徊将何见,忧思独伤心。
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:0.903毫秒