博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
任意改变FMX的TPanel控件的颜色
阅读量:6587 次
发布时间:2019-06-24

本文共 3803 字,大约阅读时间需要 12 分钟。

FMX的控件的外观以Style为主,但是也有不方便的地方,比如要任意改变TPanel的颜色,只能写代码,摸索了几天,初步实现了

 

unit FMX.JKPanelEx;interfaceuses  System.SysUtils, System.Classes, System.Types, System.UITypes, FMX.Types, FMX.Controls, FMX.Objects, FMX.Graphics,  FMX.Controls.Presentation, FMX.StdCtrls;type  TAppearanceUpdateKind = (None, Fill, Stroke, CornerSize);  TJKPanelEx = class(TPanel)  private    FAppearance: TRectangle;    FFill: TBrush;    FStroke: TStrokeBrush;    FCornerSize: Single;    FAppearanceUpdateKind: TAppearanceUpdateKind;    procedure SetFill(const Value: TBrush);    procedure SetStroke(const Value: TStrokeBrush);    procedure SetCornerSize(const Value: Single);  protected    procedure ApplyStyle; override;    procedure FreeStyle; override;    procedure FillChanged(Sender: TObject); virtual;    procedure StrokeChanged(Sender: TObject); virtual;    procedure UpdateAppearanceFill;    procedure UpdateAppearanceStroke;    procedure UpdateAppearanceCornerSize;    procedure UpdateAppearance;  public    constructor Create(AOwner: TComponent); override;    destructor Destroy; override;    property Appearance: TRectangle read FAppearance write FAppearance;  published    property Fill: TBrush read FFill write SetFill;    property Stroke: TStrokeBrush read FStroke write SetStroke;    property CornerSize: Single read FCornerSize write SetCornerSize;  end;procedure Register;implementationprocedure Register;begin  RegisterComponents('JKFMXControl', [TJKPanelEx]);end;{ TJKPanelEx }procedure TJKPanelEx.ApplyStyle;begin  inherited;  if not Assigned(FAppearance) then  begin    if not FindStyleResource
('Background', FAppearance) and (ResourceControl is TRectangle) then FAppearance := TRectangle(ResourceControl); UpdateAppearanceCornerSize; UpdateAppearanceFill; UpdateAppearanceStroke; end else begin UpdateAppearance; end;end;constructor TJKPanelEx.Create(AOwner: TComponent);begin inherited; FAppearance := nil; FAppearanceUpdateKind := TAppearanceUpdateKind.None; FFill := TBrush.Create(TBrushKind.Solid, TAlphaColor($FFE0E0E0)); FStroke := TStrokeBrush.Create(TBrushKind.Solid, TAlphaColors.Black); FFill.OnChanged := FillChanged; FStroke.OnChanged := StrokeChanged;end;destructor TJKPanelEx.Destroy;begin FreeAndNil(FFill); FreeAndNil(FStroke); inherited;end;procedure TJKPanelEx.FillChanged(Sender: TObject);begin FAppearanceUpdateKind := TAppearanceUpdateKind.Fill; ApplyStyle;end;procedure TJKPanelEx.FreeStyle;begin inherited; FAppearance := nil;end;procedure TJKPanelEx.SetCornerSize(const Value: Single);begin if FCornerSize <> Value then begin FAppearanceUpdateKind := TAppearanceUpdateKind.CornerSize; FCornerSize := Value; UpdateAppearanceCornerSize; end;end;procedure TJKPanelEx.SetFill(const Value: TBrush);begin FFill.Assign(Value);end;procedure TJKPanelEx.SetStroke(const Value: TStrokeBrush);begin FStroke.Assign(Value);end;procedure TJKPanelEx.StrokeChanged(Sender: TObject);begin FAppearanceUpdateKind := TAppearanceUpdateKind.Stroke; ApplyStyle;end;procedure TJKPanelEx.UpdateAppearance;begin case FAppearanceUpdateKind of TAppearanceUpdateKind.None: ; TAppearanceUpdateKind.Fill: UpdateAppearanceFill; TAppearanceUpdateKind.Stroke: UpdateAppearanceStroke; TAppearanceUpdateKind.CornerSize: UpdateAppearanceCornerSize; end;end;procedure TJKPanelEx.UpdateAppearanceFill;begin if FAppearance <> nil then begin FAppearance.Fill.Assign(FFill); end;end;procedure TJKPanelEx.UpdateAppearanceStroke;begin if FAppearance <> nil then begin FAppearance.Stroke.Assign(FStroke); end;end;procedure TJKPanelEx.UpdateAppearanceCornerSize;begin if FAppearance <> nil then begin FAppearance.XRadius := FCornerSize; FAppearance.YRadius := FCornerSize; end;end;end.

 

转载于:https://www.cnblogs.com/jankerxp/p/7774024.html

你可能感兴趣的文章
poj1019
查看>>
可任意自定义的UITableViewCell(转)
查看>>
C#利用反射获取对象属性值
查看>>
OpenGL FBO
查看>>
C#枚举
查看>>
pad点餐系统 内存管理的一点总结
查看>>
android图片加水印,文字
查看>>
一个C/S结构的优秀例子: 延迟补偿在C/S架构游戏协议设计和优化中的应用
查看>>
《干货集锦》——前端大牛 Addy Osmani 的15个精彩PPT
查看>>
分享:流言终结者——C语言内存管理
查看>>
ORACLE数据库设置编码
查看>>
Windows Event Log相关函数使用(1)
查看>>
Android 学习 笔记_07. XML文件解析
查看>>
常见端口列表
查看>>
什么是正则表达式
查看>>
旧的非flash版Metalink的入口
查看>>
Nuget 管理报repositories.config 访问路径被拒绝 解决办法
查看>>
存储过程传递参数时出现类型转换错误!如:varchar转换为int时出错
查看>>
python list append 相关知识点
查看>>
C# 图像编程 (1) 准备工作; 你好,空姐; 为空姐照片添加特效
查看>>