hamed
hamed

Reputation: 163

C# Drag and Drop one picture box into another picture box

I'm trying to drag and drop one picture box into another picture box. please help me! thanks Best Regards

Upvotes: 1

Views: 6594

Answers (1)

Javed Akram
Javed Akram

Reputation: 15344

See this http://www.codeguru.com/Csharp/Csharp/cs_syntax/controls/article.php/c5865

Upadated: Do a trick

    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;
    }

Problem is that I am unable to find AllowDrop property in PictureBox else it will be easy to implement by DoDragDrop()

Upvotes: 2

Related Questions