2010. március 19., péntek

How to drag and drop text from a TRichEdit to other components


I would like to select text in a TRichEdit control, then drag and drop the text on another (non TRichEdit) component (ie. TEdit or TMemo). Simulating this behavior would be fine. The drag- related events are not firing when I drag text, so I assume the drag and drop behavior is embedded in the Windows control. But I don't see any drag-related messages in the Windows SDK online help.


I've got a unit "uGenDragDrop", that implements IDropTarget (amongst others), and allows you to easily add OLE Drag and Drop support to any Delphi component (i.e. allow you to drag and drop not only within a Delphi application, but also in and out of Delphi applications).

Here is a snippet of code that implements OLE drop support for a TMemo on a form.


procedure TForm1.FormCreate(Sender: TObject);
  DTMemo := TDropTarget.Create(Memo1);
  DTMemo.AddFormat(CF_TEXT, [asComplete], [meGlobMemory]);

procedure TForm1.Memo1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
  Accept := TRUE;

procedure TForm1.Memo1DragDrop(Sender, Source: TObject; X, Y: Integer);
  Memo1.Lines.Add((Source as TStorageMedium).GetText);

Nincsenek megjegyzések:

Megjegyzés küldése