一个Picture1控件,用Picture1当容器,在Picture1上放置1 个Image1的1 个Shape1控件 完整代码Dim flag1 As Boolean Private Sub Form_Load() Shape1.BorderStyle = 3 Shape1.Visible = False Image1.Visible = False Image1.Stretch = True Image1.Picture = LoadPicture("C:\456.bmp")'把456.bmp换成你的图片 Picture1.AutoRedraw = True End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Form1.CurrentX = Image1.Left + 2 Form1.CurrentY = Image1.Top + 2End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) Image1.MousePointer = 1 Image1.MousePointer = 5 'ShowXY X, Y If Button = 1 Then OffsetX = (x - zDragX): OffsetY = (y - zDragY) xi = Image1.Left + OffsetX - Val(Image1.Width / 2) yi = Image1.Top + OffsetY - Val(Image1.Height / 2) Form1.Cls Image1.Move xi, yi End If End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Image1.Visible = False Shape1.Left = x Shape1.Top = y Image1.Left = Shape1.Left Image1.Top = Shape1.Top flag1 = True End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 1 Then If flag1 = True Then '如果是处在正在选择区域状态 Shape1.Width = Abs(x - Shape1.Left) Shape1.Height = Abs(y - Shape1.Top) Shape1.Visible = True Picture1.Refresh
Else Shape1.Visible = False End If End If End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) flag1 = False Shape1.Visible = False Image1.Visible = True Image1.Height = Shape1.Height Image1.Width = Shape1.Width End Sub
完整代码Dim flag1 As Boolean
Private Sub Form_Load()
Shape1.BorderStyle = 3
Shape1.Visible = False
Image1.Visible = False
Image1.Stretch = True
Image1.Picture = LoadPicture("C:\456.bmp")'把456.bmp换成你的图片
Picture1.AutoRedraw = True
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Form1.CurrentX = Image1.Left + 2
Form1.CurrentY = Image1.Top + 2End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Image1.MousePointer = 1
Image1.MousePointer = 5
'ShowXY X, Y
If Button = 1 Then
OffsetX = (x - zDragX): OffsetY = (y - zDragY)
xi = Image1.Left + OffsetX - Val(Image1.Width / 2)
yi = Image1.Top + OffsetY - Val(Image1.Height / 2)
Form1.Cls
Image1.Move xi, yi
End If
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Image1.Visible = False
Shape1.Left = x
Shape1.Top = y
Image1.Left = Shape1.Left
Image1.Top = Shape1.Top
flag1 = True
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
If flag1 = True Then
'如果是处在正在选择区域状态
Shape1.Width = Abs(x - Shape1.Left)
Shape1.Height = Abs(y - Shape1.Top)
Shape1.Visible = True
Picture1.Refresh
Else
Shape1.Visible = False
End If
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
flag1 = False
Shape1.Visible = False
Image1.Visible = True
Image1.Height = Shape1.Height
Image1.Width = Shape1.Width
End Sub