Dim Zoom As Double ' 保存当前放大信息 Dim Step As Double ' 增大和减小的步长 Sub ImgZoom(Action As Boolean) 'Action=True 为放大,False为缩小 Dim intTmp As Double If Action Then intTmp = Zoom + Step Else If Zoom < Step Then Exit Sub intTmp = Zoom - Step End If If Image1.Width * intTmp <= Picture1.Width And Image1.Height * intTmp <= Picture1.Height Then '如果放大缩小动作有效 Image1.Width = Image1.Width * intTmp Image1.Height = Image1.Height * intTmp Zoom = intTmp '将Image控件定在Picture1的中间 Image1.Left = (Picture1.Width - Image1.Width) / 2 Image1.Top = (Picture1.Height - Image1.Height) / 2 End If End Sub
to magicinaLiu:你的代码加入到我的程序中,没有反映 to DooDu: 能否给出具体的代码
鼠标右键双击事件 Dim flag As Boolean private Sub Form_Load() flag = False End Sub Private Sub Label1_DblClick() flag = True End Sub Private Sub Label1_MouseUP(Button As Integer, Shift As Integer, X As Single, Y As Single) If flag = True And Button = 2 Then Label1.Caption = "OK" End If End Sub
Private m_Height As Long Private m_Width As Long Private Sub Form_Load()
noisy(noisy)to magicinaLiu:你的代码加入到我的程序中,没有反映//汗。你在鼠标右击或双击事件里啊 Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) if Button =2 then ImgZoom True End if End sub Private Sub Image1_DBClick() ImgZoom False End IF
然后在MouseDown里记录鼠标动作,判断是什么键击了几下
最后,改变height和width,就是缩放了
Dim Step As Double ' 增大和减小的步长
Sub ImgZoom(Action As Boolean) 'Action=True 为放大,False为缩小
Dim intTmp As Double
If Action Then
intTmp = Zoom + Step
Else
If Zoom < Step Then Exit Sub
intTmp = Zoom - Step
End If
If Image1.Width * intTmp <= Picture1.Width And Image1.Height * intTmp <= Picture1.Height Then '如果放大缩小动作有效
Image1.Width = Image1.Width * intTmp
Image1.Height = Image1.Height * intTmp
Zoom = intTmp
'将Image控件定在Picture1的中间
Image1.Left = (Picture1.Width - Image1.Width) / 2
Image1.Top = (Picture1.Height - Image1.Height) / 2
End If
End Sub
to DooDu: 能否给出具体的代码
Dim flag As Boolean
private Sub Form_Load()
flag = False
End Sub
Private Sub Label1_DblClick()
flag = True
End Sub
Private Sub Label1_MouseUP(Button As Integer, Shift As Integer, X As Single, Y As Single)
If flag = True And Button = 2 Then
Label1.Caption = "OK"
End If
End Sub
Private m_Width As Long
Private Sub Form_Load()
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
Me.Image1.Tag = 0
Me.Image1.Stretch = True
m_Height = Me.Image1.Height
m_Width = Me.Image1.Width
End SubPrivate Sub Image1_DblClick()
If Me.Image1.Tag = 0 Then
Me.Image1.Tag = 1
Me.Image1.Width = Me.Picture1.Width
Me.Image1.Height = Me.Picture1.Height
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
Else
Me.Image1.Tag = 0
Me.Image1.Width = m_Width
Me.Image1.Height = m_Height
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
End IfEnd Sub
Private m_Width As Long
Private Sub Form_Load()
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
Me.Image1.Tag = 0
Me.Image1.Stretch = True
m_Height = Me.Image1.Height
m_Width = Me.Image1.Width
End SubPrivate Sub Image1_DblClick()
If Me.Image1.Tag = 0 Then
Me.Image1.Tag = 1
Me.Image1.Width = Me.Picture1.Width
Me.Image1.Height = Me.Picture1.Height
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
Else
Me.Image1.Tag = 0
Me.Image1.Width = m_Width
Me.Image1.Height = m_Height
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
End IfEnd Sub
剩下的就是楼上几位的算法了
这个我曾经也研究过,现在脑子不行了。
Private m_Width As Long
Private Sub Form_Load()
'初始化窗体啊
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
Me.Image1.Tag = 0
Me.Image1.Stretch = True '关键所在
m_Height = Me.Image1.Height
m_Width = Me.Image1.Width
End SubPrivate Sub Image1_DblClick()
If Me.Image1.Tag = 0 Then 'Tag属性用来判断图片目前是最大的还是小的(Tag=0 是小的)
Me.Image1.Tag = 1
Me.Image1.Width = Me.Picture1.Width
Me.Image1.Height = Me.Picture1.Height
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
Else
Me.Image1.Tag = 0
Me.Image1.Width = m_Width
Me.Image1.Height = m_Height
Me.Image1.Top = (Me.Picture1.Height - Me.Image1.Height) / 2
Me.Image1.Left = (Me.Picture1.Width - Me.Image1.Width) / 2
End IfEnd Sub结贴
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
if Button =2 then
ImgZoom True
End if
End sub
Private Sub Image1_DBClick()
ImgZoom False
End IF