RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomEdit.PasteFromClipboard Method

Pastes the contents of the Clipboard into edit control, replacing the current selection.

Pascal
procedure PasteFromClipboard;
C++
__fastcall PasteFromClipboard();

Use PasteFromClipboard to replace the selected text with the contents of the Clipboard, or, if no text is selected, to insert the contents of the Clipboard at the cursor. If the Clipboard is empty, or if it does not contain anything in CF_TEXT format, PasteFromClipboard does nothing.

Note: Calling PasteFromClipboard does the same thing as sending the edit control a WM_PASTE message.
 

C++ Examples: 

 

/*
This example uses an edit box, a rich edit control, and a
button on a form. When the user clicks the button, the first
line of text is copied from the rich edit control and pasted
into the edit box.  Note that only the text is pasted. If
the rich edit control includes any formatting information
that is not pasted into the edit control.  If the
destination were a rich edit control, the formatting
information would be copied as well.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  RichEdit1->SelectAll();
  RichEdit1->CopyToClipboard();
  Edit1->Clear();
  Edit1->PasteFromClipboard();
  RichEdit1->SetFocus();
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  RichEdit1->PlainText = False;
  RichEdit1->Lines->LoadFromFile("..\\overview.rtf");
  RichEdit1->ScrollBars = ssVertical;
}

 

Delphi Examples: 

{
This example uses an edit box, a rich edit control, and a
button on a form. When the user clicks the button, the first
line of text is copied from the rich edit control and pasted
into the edit box.  Note that only the text is pasted. If
the rich edit control includes any formatting information
that is not pasted into the edit control.  If the
destination were a rich edit control, the formatting
information would be copied as well.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.SelectAll;
  RichEdit1.CopyToClipboard;
  Edit1.Clear;
  Edit1.PasteFromClipboard;
  RichEdit1.SetFocus;
end;

procedure TForm1.FormCreate(Sender: TObject);
const
  // you may need to change this path to suit your environment
  Path = 'OverView.RTF';
begin
  RichEdit1.PlainText := False;
  RichEdit1.Lines.LoadFromFile(Path);
  RichEdit1.ScrollBars := ssVertical;
end;

 

CutToClipboard 

SelStart 

SelText 

SetSelTextBuf 

Displaying and Editing Text in a Memo Control

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!