Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
Command1.Tag = ""
End SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Command1.Tag = "In" Then
If X < 0 Or Y < 0 Or X > Command1.Width Or Y > Command1.Height Then
Command1.Tag = ""
ReleaseCapture
'Command1.ToolTipText = "命令按钮"
Command1.Caption = "离开"
End If
Else
Command1.Tag = "In"
SetCapture Command1.hwnd
Command1.Caption = "进入"
End IfEnd Sub
这是我从网上下的,你对照你的程序改一下。
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
Command1.Tag = ""
End SubPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Command1.Tag = "In" Then
If X < 0 Or Y < 0 Or X > Command1.Width Or Y > Command1.Height Then
Command1.Tag = ""
ReleaseCapture
'Command1.ToolTipText = "命令按钮"
Command1.Caption = "离开"
End If
Else
Command1.Tag = "In"
SetCapture Command1.hwnd
Command1.Caption = "进入"
End IfEnd Sub
这是我从网上下的,你对照你的程序改一下。
当鼠标离开控件的时候,会到form上,所以用form_mousemove()可以解决问题
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2880
ClientLeft = 60
ClientTop = 345
ClientWidth = 4725
LinkTopic = "Form1"
ScaleHeight = 2880
ScaleWidth = 4725
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 405
Left = 1080
TabIndex = 1
Text = "Text1"
Top = 480
Width = 2775
End
Begin VB.PictureBox Picture1
Height = 1215
Left = 1080
ScaleHeight = 1155
ScaleWidth = 2835
TabIndex = 0
Top = 1320
Width = 2895
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseEnter As Boolean
MouseEnter = (0 <= X) And (X <= Picture1.Width) And (0 <= Y) And (Y <= Picture1.Height)
If MouseEnter Then
'
SetCapture Picture1.hwnd
Text1.Text = "Mouse in picuture!"
Else
Text1.Text = "Mouse out!"
ReleaseCapture
End If
End Sub