Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:46:21+00:00 2026-05-29T09:46:21+00:00

I have a problem with DragDrop. private void Form0_Load(object sender, EventArgs e) { PictureBox

  • 0

I have a problem with DragDrop.

    private void Form0_Load(object sender, EventArgs e)
    {
        PictureBox panel1 = new PictureBox();
        PictureBox panel2 = new PictureBox();

        mainPanel.Dock = DockStyle.Fill;
        this.Controls.Add(mainPanel);

        panel1.Location = new Point(10, 10);
        panel1.Size = new System.Drawing.Size(500, 300);
        panel1.BorderStyle = BorderStyle.FixedSingle;

        Button b2 = new Button();
        b2.Location = new Point(10, 10);
        panel2.Controls.Add(b2);
        panel2.Location = new Point(10, 10);
        panel2.Size = new System.Drawing.Size(200, 100);
        panel2.BorderStyle = BorderStyle.FixedSingle;

        foreach (Control c in panel1.Controls)
        {
            c.MouseDown += new MouseEventHandler(control_MouseDown);
            c.MouseMove += new MouseEventHandler(control_MouseMove);
            c.MouseUp += new MouseEventHandler(control_MouseUp);
            c.AllowDrop = true;
        }
        panel1.AllowDrop = true;

        panel1.DragEnter += new DragEventHandler(container_DragEnter);
        panel1.DragDrop += new DragEventHandler(container_DragDrop);
        panel1.DragOver += new DragEventHandler(container_DragOver);

        foreach (Control c in panel2.Controls)
        {
            c.MouseDown += new MouseEventHandler(control_MouseDown);
            c.MouseMove += new MouseEventHandler(control_MouseMove);
            c.MouseUp += new MouseEventHandler(control_MouseUp);
            c.AllowDrop = true;
        }
        panel2.AllowDrop = true;

        panel2.DragEnter += new DragEventHandler(container_DragEnter);
        panel2.DragDrop += new DragEventHandler(container_DragDrop);
        panel2.DragOver += new DragEventHandler(container_DragOver);

        mainPanel.Controls.Add(panel1);
        mainPanel.Controls.Add(panel2);
        mainPanel.Controls.Add(pb);
    }

    private void control_MouseDown(object sender, MouseEventArgs e)
    {
        Control c = sender as Control;
        isDragging = true;
        clickOffsetX = e.X;
        clickOffsetY = e.Y;
    }

    private void control_MouseMove(object sender, MouseEventArgs e)
    {
        Control c = sender as Control;
        if (isDragging == true)
        {
            c.Left = e.X + c.Left - clickOffsetX;
            c.Top = e.Y + c.Top - clickOffsetY;
            if (c.Location.X + clickOffsetX > c.Parent.Width ||
                c.Location.Y + clickOffsetY > c.Parent.Height ||
                c.Location.X + clickOffsetX < 0 ||
                c.Location.Y + clickOffsetY < 0)

                c.DoDragDrop(c, DragDropEffects.Move);
        }
    }

    private void control_MouseUp(object sender, MouseEventArgs e)
    {
        isDragging = false;
    }

    void container_DragOver(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Move;
    }

    private void container_DragEnter(object sender, DragEventArgs e)
    {
        //e.Effect = DragDropEffects.Move;

        //if (e.Data.GetDataPresent(typeof(Bitmap)))
        //{
        //    e.Effect = DragDropEffects.Copy;
        //}
        //else
        //{
        //    e.Effect = DragDropEffects.None;
        //}
    }

    private void container_DragDrop(object sender, DragEventArgs e)
    {
        Control c = e.Data.GetData(e.Data.GetFormats()[0]) as Control;
        PictureBox p = sender as PictureBox;
        mycontrol = c;
        isDragging = false;
        if (c != null)
        {
            c.Location = p.PointToClient(new Point(e.X, e.Y));
            p.Controls.Add(c);
        }
    }

This is a working example. But I can’t do drop Controls from parent to child control. What is a magic? How to drop control to another control (from panel1 to panel2 in my example).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:46:22+00:00Added an answer on May 29, 2026 at 9:46 am

    There are some answers here in SO, which may help you:

    See this Move controls when Drag and drop on panel in C#

    this is a complete example on how to host the Form Designer:

    Tailor Your Application by Building a Custom Forms Designer with .NET

    Check this one also for simple lable drag drop:
    Basic drag and drop in WinForms

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with this method in NLog library: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state) It consume too
I have problem with pointers. This is working fine - int main(void){ char *w;
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I have problem with fancybox. I want to write a function that will run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.