Dave Nottage 557 Posted July 18, 2019 Instead of using Edit Custom Style for every component that we want a background color on, I came up with some code similar to this: type TEditEx = class(TEdit) private FColor: TAlphaColor; function GetBackgroundRectangle: TRectangle; procedure InternalSetColor(const Value: TAlphaColor); procedure SetColor(const Value: TAlphaColor); protected procedure ApplyStyle; override; published property Color: TAlphaColor read FColor write SetColor; end; procedure TEditEx.ApplyStyle; begin inherited; InternalSetColor(FColor); end; function TEditEx.GetBackgroundRectangle: TRectangle; var LStyleObject: TFmxObject; I: Integer; begin Result := nil; LStyleObject := FindStyleResource('rect'); if LStyleObject = nil then begin LStyleObject := FindStyleResource('background'); if LStyleObject <> nil then begin Result := TRectangle.Create(LStyleObject); Result.StyleName := 'rect'; Result.Align := TAlignLayout.Contents; Result.HitTest := False; Result.Stroke.Kind := TBrushKind.None; Result.Fill.Color := TAlphaColorRec.Null; Result.Parent := LStyleObject; end; end else Result := TRectangle(LStyleObject); end; procedure TEditEx.InternalSetColor(const Value: TAlphaColor); var LRectangle: TRectangle; begin LRectangle := GetBackgroundRectangle; if LRectangle <> nil then begin FColor := Value; LRectangle.Fill.Color := FColor; end; end; procedure TEditEx.SetColor(const Value: TAlphaColor); begin NeedStyleLookup; ApplyStyleLookup; InternalSetColor(Value); end; A side-effect of this code is that the inner parts of the edit control can be selected in the Object Inspector, like this: Any ideas of what I've done wrong, and how to remedy it? Share this post Link to post
f.m 8 Posted July 18, 2019 (edited) Hi, Try Result.Locked := True; Edited July 18, 2019 by f.m 2 Share this post Link to post
Dave Nottage 557 Posted July 23, 2019 On 7/19/2019 at 1:04 AM, f.m said: Result.Locked := True; We have a winner! Thanks Share this post Link to post