我希望VCL窗体的圆角可以像下图一样:
(目前只需要圆角,不需要阴影)。
我已经尝试了一些代码,但貌似没有任何变化...
这是我的结果:
![rounded corners](https://i.imgur.com/wiFADqQ.png)
unit UMainWindow;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TFMainWindow = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
FMainWindow: TFMainWindow;
implementation
procedure TFMainWindow.FormCreate(Sender: TObject);
var
rgn: HRGN;
begin
rgn := CreateRoundRectRgn(0, 0,ClientWidth,ClientHeight,40,40);
SetWindowRgn(Handle, rgn, True);
end;
end.
这是我的结果:
![不是真正的圆角](https://i.imgur.com/CtaCxsY.png)
OnCreate
事件不是创建HRGN
的最佳位置。应该重写虚拟方法CreateWnd()
或CreateWindowHandle()
。在OnCreate
事件后,窗体的HWND
可以重新创建。此外,如果窗体可调整大小,应使用OnResize
事件为新尺寸重新创建HRGN
。 - Remy Lebeau