C#将一个图片框拖放到另一个图片框中

时间:2010-12-15 07:53:06

标签: c# drag-and-drop

我正在尝试将一个图片框拖放到另一个图片框中。 请帮我! 谢谢 最诚挚的问候

1 个答案:

答案 0 :(得分:2)

请参阅此http://www.codeguru.com/Csharp/Csharp/cs_syntax/controls/article.php/c5865

<强> Upadated: 做一个技巧

    bool holdsImage = false;
    Control currentControl = null;
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        holdsImage = true;           
    }

    private void pictureBox2_MouseEnter(object sender, EventArgs e)
    {
        currentControl = pictureBox2;
    }

    private void pictureBox2_MouseLeave(object sender, EventArgs e)
    {
        currentControl = null;
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        if (holdsImage && currentControl==pictureBox2)
        {
            pictureBox2.Image = pictureBox1.Image;
            pictureBox1.Image = null;
        }
        holdsImage = false;
        currentControl = null;
    }

问题是我无法在PictureBox中找到AllowDrop属性,否则DoDragDrop()

将很容易实现