1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.Edit, FMX.Objects;
type
TEdit = class(FMX.Edit.TEdit)
private
FBackgroundRect : TRectangle;
FBackgroundColor: TAlphaColor;
procedure SetBackgroundColor(Value: TAlphaColor);
public
procedure ApplyStyle; override;
procedure FreeStyle; override;
property BackgroundColor: TAlphaColor read FBackgroundColor write SetBackgroundColor;
end;
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
{ TEdit }
procedure TEdit.ApplyStyle;
var
StyleObject: TFmxObject;
begin
inherited;
FBackgroundRect := nil;
StyleObject := FindStyleResource('backgroundcolor');
if (StyleObject <> nil) and (StyleObject is TRectangle) then
begin
FBackgroundRect := StyleObject as TRectangle;
end else begin
StyleObject := FindStyleResource('background');
if StyleObject <> nil then
begin
FBackgroundRect := TRectangle.Create(StyleObject);
StyleObject.AddObject(FBackgroundRect);
FBackgroundRect.StyleName := 'backgroundcolor';
FBackgroundRect.Align := TAlignLayout.Client;
FBackgroundRect.Stroke.Kind := TBrushKind.None;
FBackgroundRect.HitTest := False;
end;
end;
if FBackgroundRect <> nil then
FBackgroundRect.Fill.Color := FBackgroundColor;
end;
procedure TEdit.FreeStyle;
begin
FBackgroundRect := nil;
inherited;
end;
procedure TEdit.SetBackgroundColor(Value: TAlphaColor);
begin
if FBackgroundColor <> Value then
begin
FBackgroundColor := Value;
if FBackgroundRect <> nil then
FBackgroundRect.Fill.Color := Value;
end;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.BackgroundColor := TAlphaColorRec.Red;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.BackgroundColor := TAlphaColorRec.Blue;
end;
end. |
Partager