求助vb 怎样让Frame1控件在窗体上自由移动呢
运行时,要固定位置的Frame1控件用鼠标拉动起来移动至所要的位置上, 该怎么做呢
默认情况下运行后控件是固定起来了,无法用鼠标自由移动控件了。
[最优解释]
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Long
Private ptStart As POINTAPI
Private Sub StartDrag(Source As Control)
GetCursorPos ptStart
Source.Drag vbBeginDrag
End Sub
'所有界面控件的 DragDrop 事件都需要调用本方法
Private Sub StopDrop(Source As Control)
Dim ptStop As POINTAPI
GetCursorPos ptStop
With Source
.Move .Left + ScaleX(ptStop.X - ptStart.X, vbPixels, vbTwips), _
.Top + ScaleY(ptStop.Y - ptStart.Y, vbPixels, vbTwips)
End With
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
StopDrop Source
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
StopDrop Source
End Sub
Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
StartDrag Frame1
End If
End Sub
Private Sub Text1_DragDrop(Source As Control, X As Single, Y As Single)
StopDrop Source
End Sub
[其他解释]
谢谢~
[其他解释]
4124234
[其他解释]
学习下
[其他解释]
学习了,谢谢