以picture1为容器里面有个picture2,要实现下面功能。
1、在picture1中鼠标点击,把 picture2移动到该点的位置。
2、如何处理当picture2的任何一边与picture1重叠问题,不知道我说清楚了没有?大家帮个忙呀

解决方案 »

  1.   

    //2、如何处理当picture2的任何一边与picture1重叠问题,你想如何处理?
      

  2.   

    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    Picture2.Left = X
    Picture2.Top = Y
    End If
    End Sub
      

  3.   

    //2、如何处理当picture2的任何一边与picture1重叠问题,
    什么意思?
      

  4.   

    Picture2.Left = X + 一个你要附近的差距
    Picture2.Top = Y + 一个你要附近的差距
      

  5.   

    '这样行吗
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        If X + Picture2.ScaleWidth > Picture1.ScaleLeft + Picture1.ScaleWidth Then
            X = Picture1.ScaleLeft + Picture1.ScaleWidth - Picture2.ScaleWidth - 100
        End If
        If Y + Picture2.ScaleHeight > Picture1.ScaleTop + Picture1.ScaleHeight Then
            Y = Picture1.ScaleTop + Picture1.ScaleHeight - Picture2.ScaleHeight - 100
        End If
        Picture2.Left = X
        Picture2.Top = Y
    End If
    End Sub
      

  6.   

    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        If X + Picture2.ScaleWidth > Picture1.ScaleLeft + Picture1.ScaleWidth Then
            X = Picture1.ScaleLeft + Picture1.ScaleWidth - Picture2.Width
        End If
        If Y + Picture2.ScaleHeight > Picture1.ScaleTop + Picture1.ScaleHeight Then
            Y = Picture1.ScaleTop + Picture1.ScaleHeight - Picture2.Height
        End If
        Picture2.Left = X
        Picture2.Top = Y
    End If
    End Sub
      

  7.   

    始终以你的鼠标座标作为 Picture2 的左上角就可以了。
      

  8.   

    你知道PICTORE2的大小吗? 如果知道,在每移动一次的时候,都判断是否会移出P1 外,如果能移出,就为P2指定一个位置,就是说在P1 的边框附近有一个区域,鼠标怎么点P2的位置总是不变的,不知你明白我的意思不
      

  9.   

    如果你要以鼠标座标作为 Picture2 的中心点:
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim newX As Single, newY As Single
    newX = X - Picture2.ScaleWidth / 2
    newY = Y - Picture2.ScaleHeight / 2If newX < Picture1.ScaleLeft Then newX = Picture1.ScaleLeft 
    If newX + Picture2.ScaleWidth > Picture1.ScaleWidth Then newX = Picture1.ScaleWidth - Picture2.ScaleWidthIf newY < Picture1.ScaleTop Then newY = Picture1.ScaleTop
    If newY + Picture2.ScaleHeight > Picture1.ScaleHeight Then newX = Picture1.ScaleHeight - Picture2.ScaleHeightPicture2.Move  newX, newYEnd Sub
      

  10.   

    我的代码最短 你看这样行不:
    private sub picture1_MouseDown(Button as integer,Shift as integer,x as single,y as single)
     picture2.left=x: picture2.top=y
     if picture2.left<=0 then '使左边不重叠
        picture2.left=30
     else if picture2.left>= picture1.width-picture2.width then'使右边不重叠
        picture1.width-picture2.width-30
     endif
     if picture2.top<=0 then '使上边不重叠
        picture2.top=30
     else if picture2.top>=picture1.height-picture2.height then'使下边不重叠
        picture2.top=picture1.height-picture2.height -30
     endif
    试试看行不行
      

  11.   

    OLDDAN(老丹)的最好了
     baoaya(点头) 的可以
     of123() 有点问题,你在pic1的底部点击的话,那么pic2的一部份会被遮住
     wenquan836(电脑狂徒) 的可以
    结贴了
      

  12.   

    哦,错了一个字母。看来你要的不是思路,而是可以照搬的代码。If newY + Picture2.ScaleHeight > Picture1.ScaleHeight Then newY = Picture1.ScaleHeight - Picture2.ScaleHeight