Private Const GWL_STYLE = (-16) Private Const WS_THICKFRAME = &H40000 Private Const SWP_NOSIZE = &H1 Private Const SWP_NOZORDER = &H4 Private Const SWP_NOMOVE = &H2 Private Const SWP_DRAWFRAME = &H20Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 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 LongPrivate Sub ControlSize(ControlName As Control, SetTrue As Boolean) Dim dwStyle As Long dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE) If SetTrue Then dwStyle = dwStyle Or WS_THICKFRAME Else dwStyle = dwStyle - WS_THICKFRAME End If dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle) SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME End SubPrivate Sub Form_Load() ControlSize Picture1, True ControlSize Text1, True End Sub
'窗体上放 TextBox、PictureBox、CheckBox 各一个' Option ExplicitPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer) If Source Is Picture1 Then With Text1 If (X > .Left) And (Y > .Top) Then Text1.Move .Left, .Top, X - .Left, Y - .Top Picture1.Move .Left + .Width, .Top + .Height End If End With End If End SubPrivate Sub Form_Load() Picture1.DragMode = vbAutomatic Picture1.Visible = False Picture1.ZOrder Check1.Caption = "调整大小" End SubPrivate Sub Check1_Click() Picture1.Move Text1.Left + Text1.Width, Text1.Top + Text1.Height, 120, 120 Picture1.Visible = Check1.Value End SubPrivate Sub Check1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) Form_DragOver Source, Check1.Left + X, Check1.Top + Y, State End SubPrivate Sub Text1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) Form_DragOver Source, Text1.Left + X, Text1.Top + Y, State End Sub
Private Const WS_THICKFRAME = &H40000
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_DRAWFRAME = &H20Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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 LongPrivate Sub ControlSize(ControlName As Control, SetTrue As Boolean)
Dim dwStyle As Long
dwStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
If SetTrue Then
dwStyle = dwStyle Or WS_THICKFRAME
Else
dwStyle = dwStyle - WS_THICKFRAME
End If
dwStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, dwStyle)
SetWindowPos ControlName.hwnd, ControlName.Parent.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
End SubPrivate Sub Form_Load()
ControlSize Picture1, True
ControlSize Text1, True
End Sub
Option ExplicitPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
If Source Is Picture1 Then
With Text1
If (X > .Left) And (Y > .Top) Then
Text1.Move .Left, .Top, X - .Left, Y - .Top
Picture1.Move .Left + .Width, .Top + .Height
End If
End With
End If
End SubPrivate Sub Form_Load()
Picture1.DragMode = vbAutomatic
Picture1.Visible = False
Picture1.ZOrder
Check1.Caption = "调整大小"
End SubPrivate Sub Check1_Click()
Picture1.Move Text1.Left + Text1.Width, Text1.Top + Text1.Height, 120, 120
Picture1.Visible = Check1.Value
End SubPrivate Sub Check1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Form_DragOver Source, Check1.Left + X, Check1.Top + Y, State
End SubPrivate Sub Text1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Form_DragOver Source, Text1.Left + X, Text1.Top + Y, State
End Sub