Chapter 35. Providing Drag and Drop

In some ways, drag and drop performs the same task as the clipboard. Both enable one application to give data to another. The difference is that the clipboard saves data for later delivery, whereas drag and drop delivers the data immediately and is done.

In this lesson, you learn how to add drag and drop to your program so it can interact with other applications.

UNDERSTANDING DRAG AND DROP EVENTS

There are two participants in a drag and drop operation: a drag source and a drop target.

  • The drag source initiates a drag — for example, when you right-click it. It determines what data is in the drag and what kinds of operations are allowed on the drag, such as a copy or move.

  • The drop target is a potential recipient of a drag's data. When the drag moves over it, the target can decide whether it can accept the data in an offered operation such as copy or move.

To handle all of the potential interactions among the drag source, the drop target, and the user, you can use several event handlers. Some of these events occur in the drag source and others occur in the drop target.

Table 35-1 summarizes the key drag source events.

Table 35.1. TABLE 35-1

EVENT

PURPOSE

GiveFeedback

The drag has entered a valid drop target. The source can indicate the type of drop allowed. For example, it might allow Copy if the target is a Label and allow Move or Copy if the target is a TextBox.

QueryContinueDrag

The keyboard or mouse button state has changed. For example, the user may have ...

Get Stephens' Visual Basic® Programming 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.