form里有两个图形控件,一个image一个picturebox,image装载了一幅透明图片,picturebox控件相对大点,现在想按着image控件拖动到picturebox中去,希望将image的图片复制到picturebox里拖动后定下来的位置里去,因为picturebox里面本身已经有一副圆图,想将image里的图片和圆图融合到一块去,请问大侠们有什么方法。最好能给出代码,谢谢。

解决方案 »

  1.   

    Private Sub Form_Load()
       Picture1.AutoSize = -1   ' 打开 AutoSize。
     Picture1.AutoRedraw = True
    End Sub
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
     Image1.Drag   ' 拖标签轮廓。
    End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
     Set Image1.Container = Picture1
    Image1.Move X, Y
    Image1.ZOrder
    End Sub
      

  2.   

    谢谢老张,你的代码效果是满足要求了,但我想把image复制到picturebox里去,就在移动后的位置上,因为我需要计算picturebox里的像素变化,如果有点就赋1,无点就赋0,现在image独立于picturebox,所以不好计算。
      

  3.   

    Option ExplicitPrivate m_StartX As Single
    Private m_StartY As SinglePrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
        If Source Is Image1 Then
            If Not Image1.Container Is Picture1 Then Exit Sub
            Image1.Move Image1.Left + (X - m_StartX), Image1.Top + (Y - m_StartY)
        End If
    End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            m_StartX = X
            m_StartY = Y
            Image1.DragIcon = Image1.Picture
            Image1.Drag vbBeginDrag
        End If
    End SubPrivate Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
        If Source Is Image1 Then
            Set Image1.Container = Picture1
            Image1.Move X - m_StartX, Y - m_StartY
        End If
    End Sub
      

  4.   

    把image复制到picturebox指定位置去应该很难吧?
      

  5.   

    到底什么要求?不是已经将 Image 显示到 Picture1 内的指定位置了?
      

  6.   

    我在picturebox里用line函数画了图,这个图是由许多小网格组成的,网格颜色是黑色的,现在把image移到里面去,image图背景是透明的,图形整个是蓝色的,想合成一个整体,然后判断这个image图覆盖了多少网格,这些网格都有坐标值,就把覆盖的网格的坐标计算出来,您的方法移动起来位置更加合理,但是由于image和picturebox是独立的,我计算不到覆盖的坐标值,如果在picturebox里用一定的笔触(即线宽)画一条蓝色的线,把一部分网格覆盖了,就可以计算这些覆盖的网格的值。所以我想是不是应该把image复制进去picturebox才能计算呢?如果image不能做到,换成两个都是picturebox控件也可以。
      

  7.   

    方案1:改成将Image1的图片直接画到Picture1上,然后用你的方法查找坐标
    Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
        If Source Is Image1 Then
            Picture1.PaintPicture Image1.Picture, X - m_StartX, Y - m_StartY
        End If
    End Sub方案2:预先将 Image1 图片透明/蓝色的点标记在一个2纬Boolean数组中,DragDrop 时将蓝色点的坐标加上放下位置的坐标偏移就是覆盖坐标。
      

  8.   

    你要完美实现就不能用image控件。
    GDI中也只有一个alphablend函数支持alpha通道。
      

  9.   

    说明你的图片不是透明的。用256色ico足够了。
      

  10.   

    试一下吧:一定用picture1当image1的容器。Option Explicit
    Dim X As Long
    Dim Y As Long
    Private m_StartX As Single
    Private m_StartY As SinglePrivate Sub Image1_DragDrop(Source As Control, X As Single, Y As Single)
        If Source Is Image1 Then
            If Not Image1.Container Is Picture1 Then Exit Sub
            Image1.Move Image1.Left + (X - m_StartX), Image1.Top + (Y - m_StartY)
        End If
    End SubPrivate Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            m_StartX = X
            m_StartY = Y
            Image1.Drag vbBeginDrag
        End If
    End Sub
    Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
        If Source Is Image1 Then
            Set Image1.Container = Picture1
            Image1.Move X - m_StartX, Y - m_StartY
        End If
    End Sub
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Image1.Visible = True
    Image1.Top = Y
    End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then '鼠标右键
    Image1.Top = Picture1.Height
    Picture1.PaintPicture Image1.Picture, X, Y, Image1.Width, Image1.Height, 0, 0
    End If
    End Sub