Nineth Chapter-delphi Drag-and-drop programming (3)

Source: Internet
Author: User
Tags integer

9.2.2 Receive drag items

Whether a control can receive a dragged item is determined by the control's OnDragOver event. In Tabset drag, the main point is to use the location of the mouse to judge.

Procedure Tform1.tabset1dragover (Sender, Source:tobject; X, Y:integer;

State:tdragstate; var accept:boolean);

Var

Droppos:integer;

Begin

If Source = TabSet1 Then

Begin

Droppos: = Tabset1.itematpos (Point (X, Y));

Accept: = (Droppos >-1) and (Droppos <> tabset1.tabindex) and

(Droppos < TabSet1.Tabs.Count);

End

Else

Accept: = False;

End

9.2.3 Drop Drag Item

When the OnDragOver event handler returns a accept of true and the project is dropped, the Ondragdrop event processing completes the drag drop response. In the Tabset drag-and-drop instance, the position of the label is changed.

Procedure Tform1.tabset1dragdrop (Sender, Source:tobject; X, Y:integer);

Var

Oldpos:integer;

Newpos:integer;

Begin

If Source = TabSet1 Then

Begin

Oldpos: = Tabset1.tabindex;

Newpos: = Tabset1.itematpos (Point (X, Y));

if (Newpos >-1) and (Newpos <> oldpos) Then

TabSet1.Tabs.Move (Oldpos, Newpos);

End

End

9.2.4 End Drag operation

There are two ways to end a drag operation: either the user releases the mouse button or the program uses the EndDrag method to forcibly abort the drag. There are two consequences of ending a drag operation: dropping is accepted or put down is ignored.

When the drag operation ends, the source control receives a message responding to the drag end event Onenddrag.

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.