FMXTBrushGrab (Delphi)
From RAD Studio XE2 Code Examples
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 (OnKeyUp, OnMouseUp), 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
//Delphi var Form1: TForm1; myBrushObject: TBrushObject; implementation procedure TForm1.FormCreate(Sender: TObject); begin // Create the brush object and set its properties myBrushObject := TBrushObject.Create(Self); 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 := TForm2.Create(Self); end; procedure TForm1.Button1Click(Sender: TObject); beginm // 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; end; procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin // When a new character is inserted in the memo, the Magnifier Rectangle is repainted Form2.Rectangle1.Repaint; end; procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); begin // When a mouse button is released (after a text selection), the Magnifier Rectangle is repainted Form2.Rectangle1.Repaint; end; procedure TForm1.FormDestroy(Sender: TObject); begin // Free the brush object if Form2 <> nil then Form2.Release; myBrushObject.Free; end;
After running the application and clicking the button, the application should look like in the following image.
Uses
- FMX.Types.TBrush.Grab ( fr | de | ja )
- FMX.Types.TBrush ( fr | de | ja )
- FMX.Types.TBrush.Kind ( fr | de | ja )
- FMX.Types.TBrush.Gradient ( fr | de | ja )
- FMX.Types.TGradient.Color ( fr | de | ja )
- FMX.Types.TGradient.Color1 ( fr | de | ja )
- FMX.Types.TBrushGrab ( fr | de | ja )
- FMX.Types.TBrushGrab.Control ( fr | de | ja )
- FMX.Types.TBrushObject ( fr | de | ja )
- FMX.Types.TBrushObject.Create ( fr | de | ja )
- FMX.Types.TBrushObject.Brush ( fr | de | ja )
- FMX.Types.TBrushResource ( fr | de | ja )
- FMX.Types.TBrushResource.StyleResource ( fr | de | ja )
- FMX.Forms.TForm.OnCreate ( fr | de | ja )
- FMX.Types.TControl.OnClick ( fr | de | ja )
- FMX.Types.TControl.OnKeyUp ( fr | de | ja )
- FMX.Types.TControl.OnMouseUp ( fr | de | ja )