rvico TRichView Reference | TRichView

TCustomRichView.BeginOleDrag

Top  Previous  Next

Starts dragging the selection.

procedure BeginOleDrag;

(introduced in v1.9)

This method is useful if you want to implement drag&drop of inserted controls.(all other content can be dragged automatically)

Example

This example implements drag&drop of inserted TButton controls.

1) Add the following variables in form:

ClickedControl: TObject;

ClickPoint: TPoint;

2) Add the following methods:

procedure TForm1.OnControlMouseDown(Sender: TObject;

  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

begin

  if Button = mbLeft then begin

    RichViewEdit1.SelectControl(TControl(Sender));

    ClickedControl := Sender;

    ClickPoint := Point(X, Y);

  end;

end;

 

procedure TForm1.OnControlMouseMove(Sender: TObject;

  Shift: TShiftState; X, Y: Integer);

begin

  if (ssLeft in Shift) and (ClickedControl=Sender) and

    (Sqr(ClickPoint.X-X)+Sqr(ClickPoint.Y-Y)>10then

    RichViewEdit1.BeginOleDrag;

end;

3) Assign events to created controls:

  btn := TButton.Create(Self);

  btn.Caption := 'Button';

  btn.OnMouseDown := OnControlMouseDown;

  btn.OnMouseMove := OnControlMouseMove;

  RichViewEdit1.InsertControl('',btn,rvvaBaseline);

4) Events are not saved in RVF, so reassign them on loading. Use OnControlAction event:

procedure TForm1.RichViewEdit1ControlAction(Sender: TCustomRichView;

  ControlAction: TRVControlAction; ItemNo: Integer; var ctrl: TControl);

begin

  if ControlAction=rvcaAfterRVFLoad then begin

    if ctrl is TButton then begin

      TButton(ctrl).OnMouseDown := OnControlMouseDown;

      TButton(ctrl).OnMouseMove := OnControlMouseMove;

     end;

  end;

end;

The complete example can be downloaded here: http://www.trichview.com/forums/viewtopic.php?t=157


TRichView © trichview.com