我在picturebox1中画了一个image1控件,在image1中加载图片,想实现用鼠标右键双击放大图片,鼠标左键双击缩小图片的功能,请高手指点.(最好是想以双击的点为中心扩大或缩小图片)不知是否能实现,找了很多资料都没有解决,请大家帮帮忙.

解决方案 »

  1.   

    如果是image控件就简单了,首先让stretch=true
    然后在MouseDown里记录鼠标动作,判断是什么键击了几下
    最后,改变height和width,就是缩放了
      

  2.   

    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
      

  3.   

    to magicinaLiu:你的代码加入到我的程序中,没有反映
    to DooDu: 能否给出具体的代码
      

  4.   

    鼠标右键双击事件
    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
      

  5.   

    Private m_Height As Long
    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
      

  6.   

    Private m_Height As Long
    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
      

  7.   

    stretch=true
    剩下的就是楼上几位的算法了
    这个我曾经也研究过,现在脑子不行了。
      

  8.   

    Private m_Height As Long
    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结贴
      

  9.   

    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