Name
DragEventArgs
Synopsis
This class encapsulates the event arguments for the
Control.DragEnter,
Control.DragDrop, and
Control.DragOver events.
When you start a drag-drop operation using
Control.DoDragDrop(), you can specify the
DragDropEffects that the drag source can support.
Then, as the drag-drop action proceeds, controls receive
DragEnter, DragDrop, and
DragOver events, which have
DragEventArgs. You can retrieve the
AllowedEffect property to determine what the
source will permit, and then set the Effect
property to specify which you can support as a target. It will also
raise GiveFeedback events, which allow you to
determine the current Effect, perhaps changing the
Control object’s appearance or
cursors. You might base this on the KeyState.
Sadly, the KeyState has not been well
encapsulated, and you have to mess around with magic numbers in a
bitfield:
- 1
The left mouse button
- 2
The right mouse button
- 4
The Shift key
- 8
The Control key
- 16
The middle mouse button
- 32
The Alt key
You can also retrieve the actual Data that is
being dragged, through the IDataObject that
encapsulates it.
public class DragEventArgs : EventArgs { // Public Constructors public DragEventArgs(IDataObject data, int keyState, int x, int y, DragDropEffects allowedEffect, DragDropEffects effect); // Public Instance Properties public DragDropEffects AllowedEffect{get; } public IDataObject Data{get; } public DragDropEffects Effect{set; get; } public int KeyState{get; } public int X{get; } public int Y{get; } }
Hierarchy
System.Object ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access