Jump to content

Do not show drag image immediately?

Recommended Posts



I have a pagecontrol descendant, where I overridden the DoDrag method to show the picture of the dragged tab:

Procedure TPageControl.DoStartDrag(Var DragObject: TDragObject);
 tab: TRect;
 bmp, tabbmp: TBitMap;
 If DragObject <> nil Then Exit;

 // Create a bitmap of the tab button under cursor
 tab := Self.TabRect(Self.ActivePage.TabIndex);
 bmp := TBitmap.Create;
 tabbmp := TBitmap.Create;
  bmp.Height := Self.Height;
  bmp.Width := Self.Width;
  tabbmp.Height := tab.Height;
  tabbmp.Width := tab.Width;
  Self.PaintTo(bmp.Canvas.Handle, 0, 0);
  tabbmp.Canvas.CopyRect(tabbmp.Canvas.ClipRect, bmp.Canvas, tab);
  DragObject := TPageControlExtraDragObject.Create(tabbmp);

When the user clicks on one of the tabs I'm manually initiating the dragging process by Self.BeginDrag(False);. When I went into BeginDrag, I saw that if you do not specify a dragging threshold, it takes this value from Mouse.DragThreshold, which is 5 pixels. This - to me - means that the dragging is NOT initiated unless the button is still down, and the cursor went at least 5 pixels away from the initiating position.

What happens now is that the DoStartDrag event fires immediately, the bitmap is taken and is drawn as a fly-out immediately. Even it I am just switching tabs, which is kind of annoying.


So the question is... if my logic is right (and the DoStartDrag should be fired based on distance) why it is firing immediately? If not, is there a simple setting I forgot to add or I manually have to handle this by MouseMove?


I'm using Delphi 10.4.1, but the "issue" was present in 10.4 and 10.3 as well.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now