Drag-and-drop in Windows Everyone must be familiar with, such as file transfer, copy, and other operations with the mouse gently drag, in the writing program is sometimes used to drag and drop, then how to achieve it? This paper takes C + + BUILDER5 (CB5) as an example to analyze the concrete implementation of the drag-and-drop function.
A Drag and drop of the tool bar
----to implement drag-and-drop functionality, you must first understand several drag-and-drop properties and methods, and for the Tcontrol control, CB5 provides three properties, Docksite,dragkind, and DragMode. The flexibility to use these three properties will result in unexpected results. The meaning of these three attributes is:
----Docksite: Specifies whether the current control accepts drag-and-dock types of operations
----Dragkind: Drag and drop species, divided into Dkdrag and dkdock two species
----DragMode: Drag-and-drop mode, divided into two types of automatic and manual mode
----Where the dock operation refers to a control that is detached from its parent and becomes the child of another control, that is, two control merges. A control whose docksite is true indicates that it accepts a control that performs the dock operation and becomes its parent.
----The famous Office toolbar can be dragged and dropped at will, in fact it is simple: put a CoolBar control on the form, and then put a few toolbar controls on the CoolBar control, their property setting code is as follows:
Coolbar1.docksite=true;
Toolbar1.dragkind=dkdock;
Toolbar1.dragmode= dmautomatic;
----Other Toolbar property settings are the same as the ToolBar1 property settings, compile and run the program, drag the tool bar to try, cool pole.
Ii. drag-and-drop between any two controls
----Several functions related to this operation are:
----BeginDrag: Start a drag-and-drop operation, if the control's DragMode is dmmanual, you must call this function, and if DragMode is dmautomatic, do not call.
----OnDragOver: This event is triggered when a dragged object passes through this control, where the parameter accept indicates whether the object being dragged and dropped is accepted.