试图让一个图片框拖动,但它会出现问题C#

时间:2018-02-17 22:13:05

标签: c# winforms

.flow()

它有点工作,但是当你移动它时会出现故障(图片框会迅速传送到屏幕周围)。 https://www.youtube.com/watch?v=hWazyAnGNBE

1 个答案:

答案 0 :(得分:0)

您需要使用PointToClient

Form方法
var relativePoint = this.PointToClient(new Point(X, Y));

// Or

var relativePoint = this.PointToClient(Cursor.Position);

Control.PointToClient Method (Point)

  

计算指定屏幕点到客户端的位置   坐标。

更新

private void Brick_MouseMove(object sender, MouseEventArgs e)
{
    if (isDragging)
    {
        var relativePoint = this.PointToClient(Cursor.Position);
        Brick1.Left = relativePoint.X;
        Brick1.Top = relativePoint.Y;
    }
}