【问题标题】:PictureBox doesn't land on correct coordinatesPictureBox 没有落在正确的坐标上
【发布时间】:2013-06-23 15:24:11
【问题描述】:

所以我试图将图片框移动到面板上。问题是图片框没有落在鼠标的坐标上,而是落在其他地方。

    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        pictureBox1.DoDragDrop(pictureBox1,DragDropEffects.Copy);
    }

    private void panel1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;

    }

    private void panel1_DragDrop(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;
        pictureBox1.Location = new Point(e.X,e.Y);
    }

我的代码有什么问题?

【问题讨论】:

    标签: c# .net winforms drag-and-drop


    【解决方案1】:

    e.Xe.Y 表示屏幕坐标,您似乎正在寻找客户端坐标。

    pictureBox1.Location = panel1.PointToClient(new Point(e.X, e.Y));
    

    【讨论】:

    • OMG 这么多技术细节。我不知道你们回答问题的人怎么能记住这么多要点。无论如何,非常感谢你。
    • 不客气! (很多原因是之前遇到过类似的问题:D)
    猜你喜欢
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    相关资源
    最近更新 更多