C # drag-and-drop techniques related methods and events

Source: Internet
Author: User

1. Method

When implementing the drag-and-drop effect, C # provides the dodragdrop method, which is used to start the drag-and-drop operation. This method is defined by the control class, since controls are directly or indirectly derived from the control class, developers can call the dodragdrop method in any visualization component. The dodragdrop method uses the following syntax:

Public dragdropeffects dodragdrop (Object Data, dragdropeffects allowedeffects)

Data: the data content to be dragged. The content to be dragged must be passed into the first parameter location of this method.

Allowedeffects: One of the dragdropeffects enumerated values. This type contains the effects of the drag operation. The dragdropeffects enumerated values are shown in Table 32.8.

Table 32.8 dragdropeffects enumerated values

Enumeration value description
All copies, removes, and rolls data from the drag source to the target.
COPY Copies data to the destination
Link: link the data in the drag source to the destination
Move: Move the data from the drag source to the placement target.
None the destination does not accept the data.
Scroll is about to start rolling in the placement target, or is currently rolling

When using the dodragdrop method, developers must specify the allowedeffects parameter as any member of the table **. In addition, the bitwise operator can also be used, pass in any of the members as a complete parameter to get the desired drag effect, which is the key to achievingCodeAs follows:

Dragdropeffects. Copy | dragdropeffects. None

2. Events

C # provides a system drag-and-drop event, which can be used with the drag-and-drop method to achieve better results. Common drag-and-drop events are shown in the table.

Table drag-and-drop events

Description
Dragenter this event is triggered when you drag and drop the mouse cursor to the control for the first time.
Dragdrop occurs when the drag and drop operation is completed.
Givefeedback occurs during the drag operation
Dragleave event is triggered if the user moves out of a window.
Dragover: If the mouse moves but stays in the same control, the dragover event is triggered.
When the status of the keyboard or mouse button changes during the drag-and-drop operation of querycontinuedrag, The querycontinuedrag event is triggered. Querycontinuedrag event allows you to drag the source to determine whether to cancel the drag-and-drop operation

 

The following describes the important events in drag-and-drop events in detail.

(1) dragenter event

This event is triggered when you drag and drop the mouse cursor to the control for the first time.

Syntax:

Public event drageventhandler dragenter

This event is a drageventhandler delegate type. This delegate is a method specially designed to handle events related to controls such as dragenter, dragdrop, givefeedback, dragleave, and dragover. The definition syntax of the drageventhandler delegate type is as follows:

Public Delegate void drageventhandler (Object sender, drageventargs E)

The method encapsulated by this delegate must accept two parameters. The first is an object type object, which is used to specify the drag-and-drop target object. The second is the drageventargs type parameter E, it mainly contains data related to the drag operation. The attribute values and descriptions of drageventargs type parameter E are shown in the table.

Attribute values and descriptions of drageventargs type parameter E

Description
Allowedeffect: gets the drag and drop operations allowed by the initiator (or source) of the drag event.
Data obtains idataobject, which contains the data associated with this event
Effect gets or sets the target placement effect in the drag-and-drop operation.
Keystate: obtains the current status of the shift, Ctrl, and ALT keys, and the status of the mouse button.
X obtains the X coordinates of the mouse pointer in the screen coordinate system.
Y obtains the Y coordinate of the mouse pointer in the screen coordinate system.

(2) querycontinuedrag event

This event is triggered when the keyboard or mouse button status changes during the drag-and-drop operation.

Syntax:

Public event querycontinuedrageventhandler querycontinuedrag

The delegate definition syntax is as follows:

Public Delegate void drageventhandler (Object sender, querycontinuedrageventargs E)

The method encapsulated by this delegate must accept two parameters. The first is an object type object, which is used to specify as a drag-and-drop target object; the second is the querycontinuedrageventargs type parameter E, it mainly contains data related to the drag operation. Querycontinuedrageventargs type parameter E has an action attribute, which is used to determine whether to continue dragging, placing data, or canceling operations. The Action property values and descriptions are shown in Table 32.11.

Table querycontinuedrageventargs. Action attribute value and description

Description
Continue this operation will continue
Drop this operation ends with placement
The cancel Operation is canceled and no message is placed.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.