FireMonkey TBrushGrab C++ Code Example

By: Tim DelChiaro

Abstract: This example demonstrates how to use a TBrushObject and how to set the Grab property of TBrush

    FMXTBrushGrab (C++)

 

    Language:

    Versions:

 

Contents

    Description

This example demonstrates how to use a TBrushObject and how to set the Grab property of TBrush.

This example requires two forms containing the following components:

Create event handlers for the first form (OnCreate), the memo (OnKeyUpOnMouseUp), and the button (OnClick), using the Object Inspector, and insert the code below.

When modifying the text in the memo on the first form, the rectangle on the second form reflects the changes.

    Code

// C++
TForm1 *Form1;
TBrushObject *myBrushObject;
// ---------------------------------------------------------------------------
 
void __fastcall TForm1::FormCreate(TObject *Sender) {
	// Create the brush object and set its properties
	myBrushObject = new TBrushObject(this);
	myBrushObject->Brush->Kind = TBrushKind::bkGradient;
	myBrushObject->Brush->Gradient->Color = claSpringgreen;
	myBrushObject->Brush->Gradient->Color1 = claWhite;
	// Set the Style of the Form fill
	Form1->Fill->Kind = TBrushKind::bkResource;
	Form1->Fill->Resource->StyleResource = myBrushObject;
	Form2 = new TForm2(this);
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm1::Button1Click(TObject *Sender) {
	// When clicking the button, the second form appears and acts as a magnifier for the Memo on the first form
	Form2->Show();
	Form2->Rectangle1->Fill->Kind = TBrushKind::bkGrab;
	Form2->Rectangle1->Fill->Grab->Control = Memo1;
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm1::Memo1KeyUp(TObject *Sender, WORD &Key,
	System::WideChar &KeyChar, TShiftState Shift) {
	// When a new character is inserted in the Memo, the Magnifier Rectangle is repainted
	Form2->Rectangle1->Repaint();
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm1::Memo1MouseUp(TObject *Sender, TMouseButton Button,
	TShiftState Shift, float X, float Y) {
	// When a mouse button is released (after a text selection), the Magnifier Rectangle is repainted
	Form2->Rectangle1->Repaint();
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm1::FormDestroy(TObject *Sender) {
	if (Form2 != NULL) {
		Form2->Release();
	}
	delete myBrushObject;
}
// ---------------------------------------------------------------------------

After running the application and clicking the button, the application should look like in the following image.

File:TBrush_Visual1.JPG

    Uses

Server Response from: ETNASC03