FMXTBrushGrab (Delphi)

From RAD Studio XE2 Code Examples
Jump to: navigation, search

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 (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.

TBrush Visual1.JPG

Uses

See Also

Personal tools
Previous Versions