How can I change the Button shape?
Applies To: C++Builder 1 or higher
Category: Knowledge Base
- Is it possible to change the shape of my Buttons? How?
-

-
- Start a new application.
-
- Add two (2) Buttons.
-
- Edit the OnCreate event of your form and insert:
-
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Color = clWhite;
-
- HRGN ell_region = CreateEllipticRgn(2, 2,
- Button1->Width - 2, Button1->Height - 2);
- SetWindowRgn(Button1->Handle, ell_region, true);
-
- TRect r = Button2->ClientRect;
- HRGN round_region = CreateRoundRectRgn(r.Left,
- r.Top, r.Right, r.Bottom, 20, 20);
- SetWindowRgn(Button2->Handle, round_region, true);
- }
-
- You can use the CreateEllipticRgn, CreatePolygonRgn and CreateRoundRectRgn to specify a different shape for your Buttons. As you can see, the result is not always perfect. Therefore, it's recommended to create your own component instead of changing the window region.
C++Builder Developer's Network
Copyright © Yoto Yotov