RAD Studio
ContentsIndex
PreviousUpNext
Pasting Graphics from the Clipboard

If the clipboard contains a bitmapped graphic, you can paste it into any image object, including image controls and the surface of a form.

To paste a graphic from the clipboard:

  1. Call the clipboard's HasFormat method (VCL applications) to see whether the clipboard contains a graphic. HasFormat is a Boolean function. It returns True if the clipboard contains an item of the type specified in the parameter. To test for graphics on the Windows platform, you pass CF_BITMAP.
  2. Assign the clipboard to the destination.
Note: The following VCL code shows how to paste a picture from the clipboard into an image control in response to a click on an Edit->Paste
menu item:

procedure TForm1.PasteButtonClick(Sender: TObject);
var
Bitmap: TBitmap;
begin
if Clipboard.HasFormat(CF_BITMAP) then { is there a bitmap on the Windows clipboard? )
begin
Image1.Picture.Bitmap.Assign(Clipboard);
 end;
end;

 

void __fastcall TForm1::Paste1Click(TObject *Sender)
{
Graphics::TBitmap *Bitmap;
if (Clipboard()->HasFormat(CF_BITMAP)){
Image1->Picture->Bitmap->Assign(Clipboard());
  }
}

The graphic on the clipboard could come from this application, or it could have been copied from another application, such as Microsoft Paint. You do not need to check the clipboard format in this case because the paste menu should be disabled when the clipboard does not contain a supported format.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!