?? testmouseleave.frm
字號:
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
Begin VB.Form Form1
Caption = "Capture MouseLeave Event"
ClientHeight = 4260
ClientLeft = 2100
ClientTop = 1725
ClientWidth = 5895
LinkTopic = "Form1"
ScaleHeight = 4260
ScaleWidth = 5895
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 3720
TabIndex = 2
Top = 1800
Width = 2055
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 3720
TabIndex = 1
Top = 960
Width = 2055
End
Begin ComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 495
Left = 0
TabIndex = 0
Top = 3765
Width = 5895
_ExtentX = 10398
_ExtentY = 873
SimpleText = ""
_Version = 327680
BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7}
NumPanels = 1
BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7}
TextSave = ""
Key = ""
Object.Tag = ""
EndProperty
EndProperty
MouseIcon = "TestMouseLeave.frx":0000
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' 標題: 在VB中捕捉MouseLeave事件
' 作者: James Guo
' 您可以自由地在您的應用程序應用該代碼,無需征得作者的同意.
' 歡迎光臨VB天堂, 一個VB程序員的VB主頁.
' 地址: http://www.zhanjiang.gd.cn/personal/jamgsguo
' Email: jamesguo@usa.net
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' 沒有使用MouseLeave事件,當鼠標快速移動時,程序來不及響應
StatusBar1.Panels(1).Text = "This is Command1"
End Sub
Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
'判斷當前鼠標位置是否在Command2上
MouseOver = (0 <= X) And (X <= Command2.Width) And (0 <= Y) And (Y <= Command2.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠標在Command2上, 則利用SetCapture將每一個鼠標事件都傳遞給Command2
' 并在StatusBar1.Panels(1)上顯示幫助信息
StatusBar1.Panels(1).Text = "This is Command2"
SetCapture Command2.hWnd
Else
' MouseLeave Event
' 假如鼠標不在Command2上, 則利用SetCapture釋放鼠標捕捉
' 并清除在StatusBar1.Panels(1)上的幫助信息
StatusBar1.Panels(1).Text = ""
ReleaseCapture
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.Panels(1).Text = ""
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -