ドラッグして制御位置を変更します

ポイントmouseDownPoint = Point.Empty。
長方形RECT = Rectangle.Empty。
BOOL isDrag = ; 

プライベート ボイド pictureBox1_MouseDown(オブジェクト送信者、MouseEventArgs E)
{ 
    場合(e.Button == MouseButtons.Left)
    { 
        mouseDownPoint = e.Location。
        RECT = pictureBox1.Bounds。
    } 
} 

プライベート ボイド pictureBox1_MouseUp(オブジェクト送信者、MouseEventArgs E)
{ 
    場合(e.Button == MouseButtons.Left)
    { 
        場合(isDrag)
        { 
            isDrag = 
            pictureBox1.Location = rect.Location。
            この.Refresh(); 
        } 
        )(リセット。
    } 
} 

プライベート ボイド pictureBox1_MouseMove(オブジェクト送信者、MouseEventArgs E)
{ 
    場合(e.Button == MouseButtons.Left)
    { 
        isDrag = 
        rect.Location = getPointToForm(新しいポイント(e.Location.X - mouseDownPoint.X、e.Location.Y -mouseDownPoint.Y));
        この.Refresh(); 
    } 
} 

プライベート ボイドリセット()
{ 
    mouseDownPoint = Point.Empty。
    RECT = Rectangle.Empty。
    isDrag = ; 
} 
プライベートポイントgetPointToForm(点P)
{ 
    戻り 、この(pictureBox1.PointToScreen(P))を.PointToClient。
}

おすすめ

転載: www.cnblogs.com/jizhiqiliao/p/10930612.html
おすすめ