CopyMode (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses the CopyMode of an image's canvas to delete the image when you choose the Cut menu item. This example requires a Main Menu with a Copy and a Cut menu item that have their OnClick error handlers populated. Note: CopyMode and CopyRect are members of the destination canvas.

Code

void __fastcall TForm1::Copy1Click(TObject *Sender)
{
	TRect SrcRect, DstRect;

	Image2->Canvas->CopyMode = cmSrcCopy;
	DstRect = Rect(0, 0, Image2->Width, Image2->Height);
	SrcRect = Rect(0, 0, Image1->Width, Image1->Height);
	Image2->Canvas->CopyRect(DstRect, Image1->Canvas, SrcRect);
}

void __fastcall TForm1::Cut1Click(TObject *Sender)
{
	TRect r;

	Copy1Click(Sender); // Do the same thing as the copy menu item.
	Image1->Canvas->CopyMode = cmWhiteness;
	r = Rect(0, 0, Image1->Width, Image1->Height);
	Image1->Canvas->CopyRect(r, Image1->Canvas, r);
	Image1->Canvas->CopyMode = cmSrcCopy; // Restore the copy mode.
}

Uses