最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

delphi - How to dynamically create a TRectangle with rounded corners in FMX? - Stack Overflow

programmeradmin0浏览0评论

I know it's something simple, but I just don't know why my TRectangle doesn't have rounded corners.

Here's my code:

var Box2 := TRectangle.Create(Application);
Box2.Parent := Form1;
Box2.Position.X := 300;
Box2.Position.Y := 256;
Box2.Width := 177;
Box2.Height := 50;
Box2.Stroke.Thickness := 10;
Box2.XRadius := 10;
Box2.XRadius := 10;
Box2.Name := 'Whatever2';

This is how it looks:

This is how I need it to look:


What am I missing in my code in order to get the rounded corners to show?

I know it's something simple, but I just don't know why my TRectangle doesn't have rounded corners.

Here's my code:

var Box2 := TRectangle.Create(Application);
Box2.Parent := Form1;
Box2.Position.X := 300;
Box2.Position.Y := 256;
Box2.Width := 177;
Box2.Height := 50;
Box2.Stroke.Thickness := 10;
Box2.XRadius := 10;
Box2.XRadius := 10;
Box2.Name := 'Whatever2';

This is how it looks:

This is how I need it to look:


What am I missing in my code in order to get the rounded corners to show?

Share Improve this question asked 14 hours ago Shaun RoseltShaun Roselt 3,2525 gold badges27 silver badges55 bronze badges 1
  • You could have used GExperts's feature "Component to code", which would have given you the proper creation code after you designed an example with the form designer and Object Inspector first. – DelphiCoder Commented 2 hours ago
Add a comment  | 

1 Answer 1

Reset to default 4

It took a bit for me to figure out the problem, which turned out to be a typo!

You have the following lines. See anything wrong?

Box2.XRadius := 10;
Box2.XRadius := 10;

Both are X!

What found it for me was to create another box (Box1) at design time (that worked properly), then added the following to the end of your code, to see if, despite appearances, something was different.

  Assert(Box1.Corners=Box2.Corners);
  Assert(Box1.CornerType=Box2.CornerType);
  Assert(Box1.XRadius=Box2.XRadius);
  Assert(Box1.YRadius=Box2.YRadius);

I got an assertion failure on the last line (which I thought was odd; why would XRadius match but not YRadius?), then I spotted the problem.

发布评论

评论列表(0)

  1. 暂无评论