trichview.com

trichview.support




Re: Drag & Drop Controls in richviewedit


Return to index


Author

Message

Sergey Tkachenko

Posted: 11/21/2003 18:28:24


This procedure copies the dropped control:


procedure TForm1.RichViewEdit1DragDrop(Sender, Source: TObject; X,

  Y: Integer);

var Stream: TMemoryStream;

    newctrl: TComponent;

begin

  if Source is TComponent then begin

    Stream := TMemoryStream.Create;

    Stream.WriteComponent(TButton(Source));

    Stream.Position := 0;

    newctrl := Stream.ReadComponent(nil);

    TCustomRichViewEdit(Sender).InsertControl('', TControl(newctrl),

rvvaBaseline);

  end;

end;


Besides, you need to process RichViewEdit1.OnDragOver to allow accepting and

move caret.

Moving the control is more tricky. You need to

- store the original control location;

- when dropping,

  - copy it to the stream;

  - select in richviewedit and delete

  - move the caret back to the insertion position (note: it can be changed,

if the control was above it)

  - insert


May be, functions from RVLinear.pas will help



> Hi Sergey,

>

> do I have to do some kind of copying the control, insert to a new place

> and delete the old one ?

>

> Thanks

> Karsten

>

> Sergey Tkachenko wrote:

> > Hi,

> >

> > Unfortunately, TRichView cannot control dragging of inserted control, so

> > full-functional drag&drop is not possible.

> >

> > But you can use VCL drag&drop functions, like in the demo

> > Demos\Delphi\Assorted\Graphics\DragImg\

> > In this demo, controls a located outside TRichViewEdit. But there is no

> > difference - they can be inside. It's easy to copy controls. Moving is

not

> > so trivial.

> >

>

>





Powered by ABC Amber Outlook Express Converter