'添加 Image1 Label1(0) '注意Label1是数组 Index要设为0 'Image图片在处理拖动或拉大拉小都会闪,只能用API再处理,但代码长在这里不方便贴,给我邮箱吧 '使用Image原因就是它可以拉伸(Stretch属性)PictureBox没有,否则Picture就好处理了.Dim i&, oldX!, oldY!, bShow As Boolean, bMove As Boolean Private Sub Form_Load() Label1(0).Width = 75: Label1(0).Height = 75: Label1(0).BackColor = QBColor(1): Label1(0).Caption = "": Label1(0).Visible = False If Label1.Count = 1 Then For i = 1 To 7 Load Label1(i) Next End If Image1.Stretch = True bShow = False Me.Width = 8000: Me.Height = 6000: Me.Caption = "CBM666的运行时期改变图象尺寸" Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 End SubPrivate Sub Form_Click() If bShow Then bShow = False: HideLabel1s End SubPrivate Sub Form_DragDrop(Source As Control, X As Single, Y As Single) SetLabel1s Image1 End SubPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer) SizeObject Source.Index, X, Y End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.MousePointer = vbDefault End SubPrivate Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) bMove = False For i = 0 To 7 Label1(i).Visible = True Next End SubPrivate Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) HideLabel1s Label1(Index).Drag End SubPrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single) SetLabel1s Image1 End SubPrivate Sub Image1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) With Image1 Select Case Source.Index Case 0 .Top = .Top + Y .Left = .Left + X .Width = .Width - X .Height = .Height - Y Case 1 .Left = .Left + X .Width = .Width - X Case 2 .Width = .Width - X .Height = Y .Left = .Left + X Case 3 .Height = .Height - Y .Top = .Top + Y Case 4 .Height = Y Case 5 .Width = X .Height = .Height - Y .Top = .Top + Y Case 6 .Width = X Case 7 .Width = X .Height = Y End Select End With End SubPrivate Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Select Case Index Case 0, 7 Label1(Index).MousePointer = 8 Case 1, 6 Label1(Index).MousePointer = 9 Case 2, 5 Label1(Index).MousePointer = 6 Case 3, 4 Label1(Index).MousePointer = 7 End Select End SubPrivate Sub SetLabel1s(SelectedControl As Control) With SelectedControl For i = 0 To 7 Select Case i Case 0 Label1(i).Left = .Left - Label1(i).Width Label1(i).Top = .Top - Label1(i).Height Case 1 Label1(i).Left = .Left - Label1(i).Width Label1(i).Top = .Top + ((.Height - Label1(i).Height) / 2) Case 2 Label1(i).Left = .Left - Label1(i).Width Label1(i).Top = .Top + .Height Case 3 Label1(i).Left = .Left + ((.Width + Label1(i).Width) / 2) Label1(i).Top = .Top - Label1(i).Height Case 4 Label1(i).Left = .Left + ((.Width + Label1(i).Width) / 2) Label1(i).Top = .Top + .Height Case 5 Label1(i).Left = .Left + .Width Label1(i).Top = .Top - Label1(i).Height Case 6 Label1(i).Left = .Left + .Width Label1(i).Top = .Top + ((.Height - Label1(i).Height) / 2) Case 7 Label1(i).Left = .Left + .Width Label1(i).Top = .Top + .Height End Select Label1(i).Visible = True Next End With End SubPrivate Sub SizeObject(Label1Index As Integer, X As Single, Y As Single) On Error Resume Next With Image1 Select Case Label1Index Case 0 .Width = .Width + (.Left - X) .Height = .Height + (.Top - Y) .Left = X .Top = Y Case 1 .Width = .Width + (.Left - X) .Left = X Case 2 .Width = (.Left - X) + .Width .Height = Y - .Top .Left = X Case 3 .Height = .Height + .Top - Y .Top = Y Case 4 .Height = Y - .Top Case 5 .Width = X - .Left .Height = .Height + .Top - Y .Top = Y Case 6 .Width = X - .Left Case 7 .Width = X - .Left .Height = Y - .Top End Select End With KeyEdit = "Move" End SubPrivate Sub HideLabel1s() For i = 0 To 7 Label1(i).Visible = False Next End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) bMove = True oldX = X: oldY = Y End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If bMove Then Image1.Left = X - oldX + Image1.Left Image1.Top = Y - oldY + Image1.Top For i = 0 To 7 Label1(i).Visible = False Next End If End SubPrivate Sub Image1_Click() If Label1.Count = 1 Then For i = 1 To 7 Load Label1(i) Next End If bShow = True SetLabel1s Image1 End Sub 效果图: http://p.blog.csdn.net/images/p_blog_csdn_net/cbm666/366646/o_Resize.jpg
参考:http://www.china-askpro.com/msg1/qa97.shtml
'Image图片在处理拖动或拉大拉小都会闪,只能用API再处理,但代码长在这里不方便贴,给我邮箱吧
'使用Image原因就是它可以拉伸(Stretch属性)PictureBox没有,否则Picture就好处理了.Dim i&, oldX!, oldY!, bShow As Boolean, bMove As Boolean
Private Sub Form_Load()
Label1(0).Width = 75: Label1(0).Height = 75: Label1(0).BackColor = QBColor(1): Label1(0).Caption = "": Label1(0).Visible = False
If Label1.Count = 1 Then
For i = 1 To 7
Load Label1(i)
Next
End If
Image1.Stretch = True
bShow = False
Me.Width = 8000: Me.Height = 6000: Me.Caption = "CBM666的运行时期改变图象尺寸"
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
End SubPrivate Sub Form_Click()
If bShow Then bShow = False: HideLabel1s
End SubPrivate Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
SetLabel1s Image1
End SubPrivate Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
SizeObject Source.Index, X, Y
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = vbDefault
End SubPrivate Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = False
For i = 0 To 7
Label1(i).Visible = True
Next
End SubPrivate Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
HideLabel1s
Label1(Index).Drag
End SubPrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
SetLabel1s Image1
End SubPrivate Sub Image1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
With Image1
Select Case Source.Index
Case 0
.Top = .Top + Y
.Left = .Left + X
.Width = .Width - X
.Height = .Height - Y
Case 1
.Left = .Left + X
.Width = .Width - X
Case 2
.Width = .Width - X
.Height = Y
.Left = .Left + X
Case 3
.Height = .Height - Y
.Top = .Top + Y
Case 4
.Height = Y
Case 5
.Width = X
.Height = .Height - Y
.Top = .Top + Y
Case 6
.Width = X
Case 7
.Width = X
.Height = Y
End Select
End With
End SubPrivate Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Index
Case 0, 7
Label1(Index).MousePointer = 8
Case 1, 6
Label1(Index).MousePointer = 9
Case 2, 5
Label1(Index).MousePointer = 6
Case 3, 4
Label1(Index).MousePointer = 7
End Select
End SubPrivate Sub SetLabel1s(SelectedControl As Control)
With SelectedControl
For i = 0 To 7
Select Case i
Case 0
Label1(i).Left = .Left - Label1(i).Width
Label1(i).Top = .Top - Label1(i).Height
Case 1
Label1(i).Left = .Left - Label1(i).Width
Label1(i).Top = .Top + ((.Height - Label1(i).Height) / 2)
Case 2
Label1(i).Left = .Left - Label1(i).Width
Label1(i).Top = .Top + .Height
Case 3
Label1(i).Left = .Left + ((.Width + Label1(i).Width) / 2)
Label1(i).Top = .Top - Label1(i).Height
Case 4
Label1(i).Left = .Left + ((.Width + Label1(i).Width) / 2)
Label1(i).Top = .Top + .Height
Case 5
Label1(i).Left = .Left + .Width
Label1(i).Top = .Top - Label1(i).Height
Case 6
Label1(i).Left = .Left + .Width
Label1(i).Top = .Top + ((.Height - Label1(i).Height) / 2)
Case 7
Label1(i).Left = .Left + .Width
Label1(i).Top = .Top + .Height
End Select
Label1(i).Visible = True
Next
End With
End SubPrivate Sub SizeObject(Label1Index As Integer, X As Single, Y As Single)
On Error Resume Next
With Image1
Select Case Label1Index
Case 0
.Width = .Width + (.Left - X)
.Height = .Height + (.Top - Y)
.Left = X
.Top = Y
Case 1
.Width = .Width + (.Left - X)
.Left = X
Case 2
.Width = (.Left - X) + .Width
.Height = Y - .Top
.Left = X
Case 3
.Height = .Height + .Top - Y
.Top = Y
Case 4
.Height = Y - .Top
Case 5
.Width = X - .Left
.Height = .Height + .Top - Y
.Top = Y
Case 6
.Width = X - .Left
Case 7
.Width = X - .Left
.Height = Y - .Top
End Select
End With
KeyEdit = "Move"
End SubPrivate Sub HideLabel1s()
For i = 0 To 7
Label1(i).Visible = False
Next
End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bMove = True
oldX = X: oldY = Y
End SubPrivate Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Image1.Left = X - oldX + Image1.Left
Image1.Top = Y - oldY + Image1.Top
For i = 0 To 7
Label1(i).Visible = False
Next
End If
End SubPrivate Sub Image1_Click()
If Label1.Count = 1 Then
For i = 1 To 7
Load Label1(i)
Next
End If
bShow = True
SetLabel1s Image1
End Sub
效果图:
http://p.blog.csdn.net/images/p_blog_csdn_net/cbm666/366646/o_Resize.jpg