Compartir a través de


How to: Perform Drag-and-Drop Operations Between Applications

Performing drag-and-drop operations between applications is no different than enabling this action within an application, as long as both applications involved behave according to the "contract" established between the AllowedEffect and Effect properties.

In the following procedure, you will use a Windows-based application you create and the WordPad word processor that is included with the Windows operating system to perform drag-and-drop operations between applications. WordPad has a certain set of allowed effects for text being dragged and dropped; the Windows-based application you will write code for will work with these effects so that drag-and-drop operations may be completed successfully.

To perform a drag-and-drop procedure between applications

  1. Create a new Windows-based application.

    For more information, see How to: Create a Windows Application Project.

  2. Add a TextBox control to your form.

  3. Configure the TextBox control to receive dropped data.

    For more information, see Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms.

  4. Run your Windows-based application, and while the application is running, run WordPad.

    WordPad is a text editor installed by Windows that allows drag-and-drop operations. It is accessible by pressing the Start button, selecting Run, and then typing WordPad into the text box of the Run dialog box and clicking OK.

  5. Once WordPad is open, type a string of text into it.

  6. Using the mouse, select the text, and then drag the selected text over to the TextBox control in your Windows-based application.

    Observe that when you mouse over the TextBox control (and, consequently, raise the DragEnter event), the cursor changes, and you can drop the selected text into the TextBox control.

    Additionally, you can configure your TextBox control to allow text strings to be dragged and dropped into WordPad. For more information, see Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms.

See Also

Tasks

How to: Add Data to the Clipboard
How to: Retrieve Data from the Clipboard

Other Resources

Drag-and-Drop Operations and Clipboard Support