第2个回答 2009-08-19
我不是来回答此题的 只是想与你分享一下另一个有点小白的思路
首先在窗体上放置5个PictureBox,把图片装入到Picture1,然后在代码栏中输入
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Dim blnDragging As Boolean
Dim offsetX As Single, offsetY As Single
Private Sub Form_Load()
'1
Picture1.Left = 0
Picture1.Top = 0
Picture1.AutoSize = True
'2
Picture2.Left = 0
Picture2.Top = 0
Picture2.Width = 4600
Picture2.Height = 500
'3
Picture3.Left = 0
Picture3.Top = Picture2.Height
Picture3.Width = 600
Picture3.Height = 2800
'4
Picture4.Left = Picture3.Width
Picture4.Top = Picture3.Height
Picture4.Width = Picture2.Width
Picture4.Height = Picture2.Height
'5
Picture5.Left = Picture2.Width
Picture5.Top = 0
Picture5.Width = Picture3.Width
Picture5.Height = Picture3.Height
'form
Me.BorderStyle = 0
Me.Width = Picture2.Width + Picture3.Width
Me.Height = Picture2.Height + Picture3.Height
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDragging Then
Picture1.Move X - offsetX, Y - offsetY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDragging = False
ReleaseCapture
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
blnDragging = True
SetCapture Me.hwnd
offsetX = X
offsetY = Y
End If
End Sub
其实就是把4个PictureBox(也可以是其他控件)摆成一个遮罩层放在底图的上方,然后使底图可以随意拖动。代码中Form_Load事件里的代码是为了设置控件们的属性,可以不用代码直接在控件的属性里设置。其它的完善功能(如限制Picture1拖动范围等)我就不写了。