RAD Studio |  |

Cutting Graphics to the Clipboard
See Also
Collapse All

Cutting a graphic to the clipboard is exactly like copying it, but you also erase the graphic from the source.

To cut a graphic from a picture to the clipboard, first copy it to the clipboard, then erase the original.

In most cases, the only issue with cutting is how to show that the original image is erased. Setting the area to white is a common solution, as shown in the following code that attaches an event handler to the OnClick event of the EditCut menu item:

Copy Code

    procedure TForm1.Cut1Click(Sender: TObject);
    var
    ARect: TRect;
    begin
    Copy1Click(Sender);{ copy picture to clipboard }
    with Image.Canvas do
    begin
    CopyMode := cmWhiteness;{ copy everything as white }
    ARect := Rect(0, 0, Image.Width, Image.Height);{ get bitmap rectangle }
    CopyRect(ARect, Image.Canvas, ARect);{ copy bitmap over itself }
    CopyMode := cmSrcCopy;{ restore normal mode }
    end;
    end;

Copy Code

    void __fastcall TForm1::Cut1Click(TObject *Sender)
    {
      TRect ARect;
      Copy1Click(Sender);          // copy picture to clipboard
      Image->Canvas->CopyMode = cmWhiteness; // copy everything as white
      ARect = Rect(0, 0, Image->Width, Image->Height); // get dimensions of image
      Image->Canvas->CopyRect(ARect, Image->Canvas, ARect); // copy bitmap over self
      Image->Canvas->CopyMode = cmSrcCopy; // restore default mode
    }

See Also

Copying Graphics to the Clipboard

Pasting Graphics from the Clipboard

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