改变 TMemo 的背景颜色 (Firemonkey)

时间:2024-07-06 19:06:50

说明:展示使用程序码改变 Firemonkey TMemo 的背景颜色。

适用:XE6

源码下载:[原創]Memo改背景色_XE6.zip

//------------------------------------------------------------------------------
// by [龟山]阿卍 QQ:
// http://www.cnblogs.com/onechen/
//------------------------------------------------------------------------------ unit Main; interface uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
System.UIConsts, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Layouts, FMX.Memo; type
TForm1 = class(TForm)
ToolBar1: TToolBar;
Memo1: TMemo;
Label1: TLabel;
procedure Memo1ApplyStyleLookup(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx} procedure TForm1.Memo1ApplyStyleLookup(Sender: TObject);
var Obj: TFmxObject;
Rectangle1: TRectangle;
begin
Obj := Memo1.FindStyleResource('background');
if Obj <> nil then
begin
TControl(Obj).Margins := TBounds.Create(TRectF.Create(-, -, -, -));
Rectangle1 := TRectangle.Create(Obj);
Obj.AddObject(Rectangle1);
Rectangle1.Align := TAlignLayout.Client;
Rectangle1.Fill.Color := claYellow;
Rectangle1.Stroke.Color := claNull;
Rectangle1.HitTest := False;
Rectangle1.SendToBack;
end;
end; end.