改变 TMemo 的背景颜色 (Firemonkey)

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

适用:XE6

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

//------------------------------------------------------------------------------
// by [龟山]阿卍 QQ:1467948783
// 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(-2, -2, -2, -2));
          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.
posted @ 2014-04-25 10:53  龟山Aone  阅读(3599)  评论(1编辑  收藏  举报