比如窗体名字为frmMain,你允许用户拖动picTitleBar来拖动窗体
'定义变量
Dim MoveFrm As Boolean
Dim oldleft As Integer
Dim oldtop As Integer
Dim oldx As Integer
Dim oldy As Integer
'鼠标按下时
Private Sub picTitlebar_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
MoveFrm = True
oldleft = frmMain.Left
oldtop = frmMain.Top
oldx = X + frmMain.Left
oldy = Y + frmMain.Top
End If
End Sub
'鼠标移动时
Private Sub picTitlebar_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 And MoveFrm = True Then
Dim thisx As Integer, thisy As Integer
thisx = X + frmMain.Left
thisy = Y + frmMain.Top
frmMain.Left = oldleft + thisx - oldx
frmMain.Top = oldtop + thisy - oldy
End If
End Sub
'鼠标松开时
Private Sub picTitlebar_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
MoveFrm = False
End If
End Sub