C# Drag and Drop sample

Posted on 2006-04-23
Last Modified: 2012-05-05
I need to implement drag and drop between two MDI child forms. If somebody wants to paste sample code, it can include two different MDI child forms of different classes. MDI parent contains one instance of each type. Let's say that dragging starts in one form and finishes in another.  When information is dropped, destination form can show coordinates where dragging was started.
This is simple and close to desired scenario for my program.
Question by:AlexFM
    LVL 11

    Expert Comment

    what do you want to drag and drop?
    LVL 48

    Author Comment

    Source form contains image thumbnails. Destination page contains cells which can accept image or images. User can select one or more thumbnails on the source page, drag them to destination form and drop to free cell. Images are written to free cells starting from this free cell.
    I don't have implementation details yet, because both these forms are not written. Therefore, I need to see a way to pass any information from one form to another, which may be, for example, source point coordinates, or anything else.
    I want to know also how to set cursor when it is dragged over areas allowed and not allowed for dropping.
    LVL 85

    Accepted Solution

    Hey AlexFM...

    See here for the "big picture":

    Basically you set the AllowDrop() property for whatever you want to receive things.  Then in the DragEnter() event, you test the data being sent to see if it is a format you want to receive.  If so, you set the e.Effect parameter accordingly.  I created my own DataObject class to handle this situation so I know exactly what is being dropped and I can use that to base my decision upon.  You can add whatever you want to that class so you could hold multiple things in it.  Finally in the DragDrop() event you pull the data object out and do something with it...
    LVL 48

    Author Comment

    Great, this is good start point.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now