Board index » delphi » How to: Copy menu - Right click in TRichEdit

How to: Copy menu - Right click in TRichEdit

Hi,
how can I activate the right click in a TRichEdit, to copy/cut/paste text
like is the TMemo standard behavior?
Regards
Mauricio
 

Re:How to: Copy menu - Right click in TRichEdit


Quote
MLumbrer wrote:
> Hi,
> how can I activate the right click in a TRichEdit, to copy/cut/paste text
> like is the TMemo standard behavior?
> Regards
> Mauricio

You'll have to add a TPopupMenu and add the functionality yourself.  Here is
some code to help you out.

{OnPopup event}
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var
  Selected: boolean;
  L: integer;
begin
  {behave like standard edit menu}
  Selected := RichEdit1.SelLength > 0;
  mnuCopy.Enabled := Selected;
  mnuCut.Enabled := Selected;
  m{*word*198}lete.Enabled := Selected;
  mnuUndo.Enabled := RichEdit1.Modified;
  L := Length(RichEdit1.Text);
  mnuSelectAll.Enabled := (L > 0) and (L <> RichEdit1.SelLength-2);
  mnuPaste.Enabled := Clipboard.HasFormat(CF_TEXT);
end;

procedure TForm1.mnuCopyClick(Sender: TObject);
begin
  RichEdit1.CopyToClipboard;
end;

procedure TForm1.mnuCutClick(Sender: TObject);
begin
  RichEdit1.CutToClipboard;
end;

procedure TForm1.mnuPasteClick(Sender: TObject);
begin
  RichEdit1.PasteFromClipboard;
end;

procedure TForm1.mnuUndoClick(Sender: TObject);
begin
  RichEdit1.Undo;
end;

procedure TForm1.m{*word*198}leteClick(Sender: TObject);
begin
  RichEdit1.ClearSelection;
end;

procedure TForm1.mnuSelectAllClick(Sender: TObject);
begin
  RichEdit1.SelectAll;
end;

Other Threads