Delphi How To Control Windows 11 Rounded Corners In Your App

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
How To Control Windows 11 Rounded Corners In Your App
By Ian Barker September 10, 2021

1631603816884.png
As I hope you’re aware by now – Для просмотра ссылки Войди или Зарегистрируйся is now available! RAD Studio 11 contains a whole ton of features and it’s launching just ahead of Microsoft’s official release of the beautifully redesigned Windows 11. We wrote about the many great things contained in Windows 11 Для просмотра ссылки Войди или Зарегистрируйся and how behind that gorgeously aesthetic user interface are a few traps and pitfalls which may be a problem for older legacy apps and hardware.
1631603831159.png
One of the most obvious user interface changes is the fact that almost all app windows and many user interface controls will get a rounded corner effect applied to them. The amount of rounding of the application’s forms and things like text boxes, panels and group boxes will vary. Microsoft go into a lot more detail on how it will affect user interface components here in Для просмотра ссылки Войди или Зарегистрируйся.

They also have an article, Для просмотра ссылки Войди или Зарегистрируйся, which describes how the rounding of the application forms occurs and also how to turn that rounding feature on or off. Microsoft recognizes that some app windows are not going to work very well with rounding applied to the caption bar – for example tool window type application frames which typically have a very narrow height and custom-drawn window icons.

Thinking ahead, Windows 11 provides a fairly easy to use Windows API which allows you full control over that rounding behavior – to turn it off, on, or ask Windows 11 to round the windows with a smaller radius.
1631603858272.png
1631603879602.png
The question came up during the RAD Studio 11 launch Q & A whether the Embarcadero team had an example of using that API. David (or Marco, it wasn’t clear) pasted a short example of how to do it in the question window but it was a little hard to read and only a partial example so I’ve taken that answer and built a more complete demo for you to download and play with. Just for fun it also shows Windows notifications using the Для просмотра ссылки Войди или Зарегистрируйсяcomponent because if we’re going to be modern we might as well embrace a few of the other cool modern Windows things Delphi makes very easy.



1631603906471.png
RAD Studio 11 Delphi example rounded corners app running on Windows 11

On versions of Windows before Windows 11 the API call will have no effect and your app Windows will still look the same. On Windows 11 the example app controls the main form Window based on your choices from a radio group. I’ve created a universal unit with a simple call in there – all you need to do is pass it a Window handle and Windows 11 will do your bidding.
1631603936706.png
RAD Studio 11 is High DPI aware – so my screenshots look better now too!

The example app is written in the new RAD Studio 11 Alexandria, of course, but it should work on earlier versions of Delphi. To use the code in your own apps simply download the source repository from the GitHub link below and include the “delphi_rounded_corners.pas” unit in your apps and make the procedure call.

You can download the full source for the example RAD Studio 11 Delphi example application from here: Для просмотра ссылки Войди или Зарегистрируйся