如何拖动一个没有标题栏的窗体?
如何拖动一个没有标题栏的窗体? 问题点数:20、回复次数:5Top
1 楼ch21st(www.blanksoft.com)回复于 2003-06-03 13:10:45 得分 6
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'Public Const WM_SYSCOMMAND = &H112
'Public Const SC_MOVE = &HF012
Public Const HTCAPTION = 2
Public Const WM_NCLBUTTONDOWN = &HA1
If Button = vbLeftButton Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End IfTop
2 楼hengxin54(火星)回复于 2003-06-03 13:18:13 得分 5
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 Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, &HA1, HTCAPTION, 0
End SubTop
3 楼Fearfulness(谁都知道我最拽)回复于 2003-06-03 13:21:47 得分 2
在窗体的MouseMove事件里面加一些代码,可以实现.
x1,y1,为单击坐标form1.left=x-x1+form1.left .top=y-y1+.top
要是用api可以看楼上的.Top
4 楼bydisplay(时光)回复于 2003-06-03 13:24:18 得分 4
Option Explicit
'Variables
'Switch to turn drah on and off.
Dim MoveScreen As Boolean
'Vars to get the mouse position on the form.
' you are draging.
Dim MousX As Integer
Dim MousY As Integer
'Vars for moving the form.
Dim CurrX As Integer
Dim CurrY As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveScreen = True ' make form movable while the mouse is down.
'Get the initial coordinates of the mouse on the form.
MousX = X
MousY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'If the mouse is down on the form then.
If MoveScreen Then
'Calculate the new x,y position for the form.
' NB. This is dependant on the X and Y vars on the Form_MouseMove,
' you can use objects MouseMove function. i.e. a Label or Textbox.
CurrX = Form1.Left - MousX + X
CurrY = Form1.Top - MousY + Y
'Move the form to the new X,Y.
Form1.Move CurrX, CurrY ' move form.
End If
'Display the new X,Y position of the form.
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveScreen = False ' stop the form from moving.
End Sub
Top
5 楼btone(子陵)回复于 2003-06-03 13:25:18 得分 3
Private Sub Form1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseIsDown = True
cx = X
cy = Y
End Sub
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If mouseIsDown Then
'移动窗体
Move Left + (X - cx), Top + (Y - cy)
End If
End Sub
Private Sub Form1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseIsDown = False
End SubTop




