vb中加载了张图,如果用鼠标左键按着图移动就可以直接移动窗体

来源:百度知道 编辑:UC知道 时间:2024/05/24 17:08:14
就是拖动控件,form1就跟着移动 和windows标题栏一样
就不能加点注释吗?如果你的代码没问题在加点注释好理解些啊。

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 Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Picture1_Mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call ReleaseCapture
Call SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub

SendMessage就是向系统发送消息,这里就是在按下并移动鼠标师向系统发送消息,然系统误以为是在标题栏按下的。

'把下面第一行放在代码的最前面
Dim m, n As Integer

'如果你用Image1,就不用更改,否则按实际情况改动为 Picture1_MouseDown 或其他
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
m = Width - x
n = Height - y
End If
End Sub

'此处同上
Private Sub Image1_MouseMove(Button As Integer,