Dim moused As Boolean Dim startx As Integer Dim starty As Integer Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then moused = True startx = X starty = Y End If End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If moused Then Me.Top = Me.Top + Y - starty Me.Left = Me.Left + X - startx End If End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) moused = False End Sub 这样就没有限制
Private Const WM_NCLBUTTONDOWN = &HA1 Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbKeyLButton Then ReleaseCapture SendMessage hWnd, WM_NCLBUTTONDOWN, 2, 0 end if end sub
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 LongConst WM_NCLBUTTONDOWN = &HA1 Const HTCAPTION = 2Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then ReleaseCapture Call SendMessage(me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub
谢谢 zyl910(910:分儿,我来了!)
'设置窗体的BoreerStyle=0 Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As LongPrivate Type PointAPI x As Long: y As Long End TypePrivate DownPos As PointAPI, FormSize As PointAPIPrivate Sub Form_DblClick() Unload Me End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then '----------------------标记 '设置坐标系为自定义方式 Form1.ScaleMode = 3 '设置素式及绘制线粗细 Form1.DrawStyle = 0: Form1.DrawWidth = 3 PSet (x, y), vbRed '-------------------------- DownPos.x = x: DownPos.y = yFormSize.x = Form1.ScaleWidth FormSize.y = Form1.ScaleHeight End If End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then Dim NowPos As PointAPI GetCursorPos NowPos NowPos.x = NowPos.x - DownPos.x '- 4 NowPos.y = NowPos.y - DownPos.y '- 22 MoveWindow Form1.hwnd, NowPos.x, NowPos.y, FormSize.x, FormSize.y, 1 End If End Sub 春天不是读书天 夏日炎炎正好眠 秋高气爽踢球去 卖了书本好过年: D ------------------------------- 海纳百川,有容乃大; 壁立千仞,无欲则刚。
Dim startx As Integer
Dim starty As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
moused = True
startx = X
starty = Y
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If moused Then
Me.Top = Me.Top + Y - starty
Me.Left = Me.Left + X - startx
End If
End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
moused = False
End Sub
这样就没有限制
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbKeyLButton Then
ReleaseCapture
SendMessage hWnd, WM_NCLBUTTONDOWN, 2, 0
end if
end sub
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongConst WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
Call SendMessage(me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&)
End If
End Sub
Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As LongPrivate Type PointAPI
x As Long: y As Long
End TypePrivate DownPos As PointAPI, FormSize As PointAPIPrivate Sub Form_DblClick()
Unload Me
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
'----------------------标记
'设置坐标系为自定义方式
Form1.ScaleMode = 3
'设置素式及绘制线粗细
Form1.DrawStyle = 0: Form1.DrawWidth = 3
PSet (x, y), vbRed
'--------------------------
DownPos.x = x: DownPos.y = yFormSize.x = Form1.ScaleWidth
FormSize.y = Form1.ScaleHeight
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
Dim NowPos As PointAPI
GetCursorPos NowPos
NowPos.x = NowPos.x - DownPos.x '- 4
NowPos.y = NowPos.y - DownPos.y '- 22
MoveWindow Form1.hwnd, NowPos.x, NowPos.y, FormSize.x, FormSize.y, 1
End If
End Sub
春天不是读书天
夏日炎炎正好眠
秋高气爽踢球去
卖了书本好过年: D
-------------------------------
海纳百川,有容乃大;
壁立千仞,无欲则刚。