delphi – Firemonkey使用stylebook隐藏圆角溢出
在firemonkey我试图使用带圆角的矩形制作进度条.最简单的情况是一个矩形(进度条)和其中的第二个矩形(进展到现在).附上一个简单的例子.
带角落的进度条(油漆): 我尝试过以下的事情: >让第二个矩形也有圆角.这不起作用,因为如果第二个矩形非常短或几乎在最后,这些舍入将会改变. 什么工作: >有一种非常难看的方法可以完成这项工作.我现在使用那种方法,但我真的希望你能帮助我找到另一种解决方案.丑陋的方法是: 这是我们可以避免的,或者这是唯一可行的解??决方案吗? 进度条目标(油漆): 先感谢您! 一月 解决方法
我不确定你的意思
我通过使用一个Rectangle作为边框来实现这一点;在那个进程的布局之上,其中包含另一个Rectangle.第二个Rectangle总是具有第一个的尺寸(这意味着角看起来相同),Layout的ClipChildren设置为true,并通过设置其宽度来控制进度. 这是我实现它的方式: type TRoundProgressBar = class (TLayout) strict private FProgress: Single; FFill: TBrush; FStroke: TStrokeBrush; StrokeRect,FillRect: TRectangle; FillLayout: TLayout; procedure SetFill(const Value: TBrush); procedure SetStroke(const Value: TStrokeBrush); procedure FillChanged(Sender: TObject); procedure StrokeChanged(Sender: TObject); procedure SetProgress(Progress: Single); procedure UpdateWidths; protected procedure Resize; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property Fill: TBrush read FFill write SetFill; property Stroke: TStrokeBrush read FStroke write SetStroke; property Progress: Single read FProgress write SetProgress; end; implementation constructor TRoundProgressBar.Create(AOwner: TComponent); begin inherited Create(AOwner); FFill := TBrush.Create(TBrushKind.Solid,$FFE0E0E0); FFill.OnChanged := FillChanged; FStroke := TStrokeBrush.Create(TBrushKind.Solid,$FF000000); FStroke.OnChanged := StrokeChanged; FillLayout := TLayout.Create(self); FillLayout.Parent := self; FillLayout.Align := TAlignLayout.Left; FillLayout.ClipChildren := true; FillRect := TRectangle.Create(FillLayout); FillRect.Parent := FillLayout; FillRect.Align := TAlignLayout.Left; FillRect.XRadius := 15; FillRect.YRadius := 15; StrokeRect := TRectangle.Create(self); StrokeRect.Parent := self; StrokeRect.Align := TAlignLayout.Contents; StrokeRect.XRadius := 15; StrokeRect.YRadius := 15; StrokeRect.Fill.Kind := TBrushKind.None; end; destructor TRoundProgressBar.Destroy; begin FFill.Free; FStroke.Free; inherited; end; procedure TRoundProgressBar.SetFill(const Value: TBrush); begin FFill.Assign(Value); end; procedure TRoundProgressBar.SetProgress(Progress: Single); begin FProgress := Min(Max(Progress,0),100); UpdateWidths; end; procedure TRoundProgressBar.FillChanged(Sender: TObject); begin FillRect.Fill.Assign(FFill); end; procedure TRoundProgressBar.Resize; begin inherited; UpdateWidths; end; procedure TRoundProgressBar.SetStroke(const Value: TStrokeBrush); begin FStroke.Assign(Value); end; procedure TRoundProgressBar.StrokeChanged(Sender: TObject); begin StrokeRect.Stroke.Assign(FStroke); end; procedure TRoundProgressBar.UpdateWidths; begin FillRect.Width := Width; FillLayout.Width := Width * (FProgress / 100); Repaint; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |