7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private mouse_old_x As Single, mouse_old_y As Single
Private flag_on_drag As Boolean
Private Sub Form_Load()
flag_on_drag = False
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (vbLeftButton = Button) Then
mouse_old_x = X
mouse_old_y = Y
flag_on_drag = True
End If
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If True = flag_on_drag Then
Text1.Left = Text1.Left + (X - mouse_old_x)
Text1.Top = Text1.Top + (Y - mouse_old_y)
End If
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (vbLeftButton = Button) Then
flag_on_drag = False
End If
End Sub
Option Explicit
Private Const HWND_TOPMOST = -1
Private Const SWP_NOSIZE = &H1
Private Const WM_SYSCOMMAND = &H112&
Private Const SC_MOVE = &HF012&
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
'Ϊµ±Ç°µÄÓ¦ÓóÌÐòÊÍ·ÅÊó±ê²¶»ñ
ReleaseCapture
'Òƶ¯´°Ìå
SendMessage Text1.hwnd, WM_SYSCOMMAND, SC_MOVE, 0
End If
End Sub
Dim xStart As Long, yStart As Long
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
xStart = X
yStart = Y
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Text1
If Button = 1 Then
.Move .Left + X - xStart, .Top + Y - yStart
End If
End With
End Sub