-1

I have a richedit(richedit1) and a listbox(listbox1),
I want to drag the richedit1.text without affecting its text selection. here some code:

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;State: TDragState; var Accept: Boolean);
begin
     Accept := (Source is TRichEdit) ;
end;     

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
    if Source is TRichEdit then ListBox1.Items.Add(RichEdit1.SelText);
end;

When i set RichEdit1.DragMode to dmAutomatic, draging works fine, but i can not select text in richedit by mouse.
I know one solution is Like this:

procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (Sender is TCustomRichEdit) and (ssCtrl in Shift) then
       TCustomRichEdit(Sender).BeginDrag(False);
end;  

But i don't want to drag by holding ctrl key;
Do you have any better idea?

Kara
  • 6,115
  • 16
  • 50
  • 57
  • - *"..draging works fine, but i can not select text in richedit by mouse.."* - I wonder why. I dropped a TRichEdit on a brand new VCL Forms Application, and selecting by mouse and then automatic dragging works fine. I tested this on D7, D2007 and XE2. – Sertac Akyuz Feb 17 '14 at 20:49
  • Sertac, I also tested your example in Delphi XE5, but it did not work. – Mohsen Noroozi Feb 18 '14 at 14:08

1 Answers1

0

In the OnMouseDown event, you can detect if the mouse is being clicked inside of an existing selection that is 1+ characters in size, and if so then start dragging. Look at the EM_CHARFROMPOS and EM_GETSEL messages for that.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770