Edit

Share via


Drag-and-Drop Operations and Clipboard Support

You can enable user drag-and-drop operations within a Windows-based application by handling a series of events, most notably the DragEnter, DragLeave, and DragDrop events.

You can also implement user cut/copy/paste support and user data transfer to the Clipboard within your Windows-based applications by using simple method calls.

.NET 10 Compatibility

Starting with .NET 9, BinaryFormatter was removed from the runtime due to security vulnerabilities. This removal broke clipboard and drag-and-drop operations for custom objects, creating a functionality gap for Windows Forms applications.

.NET 10 addresses this issue by introducing new APIs that restore clipboard and drag-and-drop functionality while improving security, error handling, and cross-process compatibility. These APIs use JSON serialization and provide type-safe methods for data operations.

Key improvements in .NET 10 include:

  • Type-safe data retrieval with TryGetData<T>() methods that provide better error handling.
  • JSON serialization for custom types using SetDataAsJson<T>() methods.
  • Built-in support for common data types without requiring binary serialization.

For comprehensive guidance on updating your applications, see Clipboard and drag-and-drop changes in .NET 10.

In This Section

Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms
Explains how to start a drag-and-drop operation.

How to: Perform Drag-and-Drop Operations Between Applications
Illustrates how to accomplish drag-and-drop operations across applications.

How to: Add Data to the Clipboard
Describes how to programmatically insert information on the Clipboard, including the new type-safe APIs available in .NET 10.

How to: Retrieve Data from the Clipboard
Describes how to access data stored on the Clipboard using both legacy methods and the new type-safe TryGetData<T>() methods.

Clipboard and drag-and-drop changes in .NET 10
Comprehensive guide for migrating clipboard and drag-and-drop code to the new .NET 10 APIs and understanding the removal of BinaryFormatter.

Drag-and-Drop Functionality in Windows Forms
Describes the methods, events, and classes used to implement drag-and-drop behavior.

QueryContinueDrag Describes the intricacies of the event that asks permission to continue the drag operation.

DoDragDrop Describes the intricacies of the method that's central to beginning a drag operation.

Clipboard Also see How to: Send Data to the Active MDI Child.