gpt4 book ai didi

Delphi XE2风格绘画

转载 作者:行者123 更新时间:2023-12-03 15:52:54 25 4
gpt4 key购买 nike

在绘制 VCL 样式的窗口元素时,我遇到了错误绘制角点的问题。在具有圆角的样式上,我在控件的边界矩形和样式的圆角窗口角之间的空间中得到白色背景。

enter image description here

上图是使用 Aqua Light Slate 运行的,但任何带有圆角的样式都会出现同样的问题。我错过了什么?

type
TSample = class(TCustomControl)
protected
procedure Paint; override;
end;

{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
R: TRect;
S: TSample;
begin
R := ClientRect;
InflateRect(R, -20, -20);
S := TSample.Create(Application);
S.Parent := Self;
S.BoundsRect := R;
end;

{ TSample }
procedure TSample.Paint;
var
Details: TThemedElementDetails;
begin
Details := StyleServices.GetElementDetails(twCaptionActive);
StyleServices.DrawParentBackground(Self.Handle, Canvas.Handle, Details, False);
StyleServices.DrawElement(Canvas.Handle, Details, ClientRect);
end;

最佳答案

好的,我花了几分钟回答你的问题并找到了答案。绘制圆角的关键是调用 StyleServices.GetElementRegion函数获取区域,然后使用 SetWindowRgn函数将区域应用到控件。

检查此示例

procedure TSample.Paint;
var
Details : TThemedElementDetails;
Region : HRgn;
LRect : TRect;
begin
Details := StyleServices.GetElementDetails(twCaptionActive);
LRect := Rect(0, 0, Width, Height);
StyleServices.GetElementRegion(Details, LRect, Region);
SetWindowRgn(Handle, Region, True);
StyleServices.DrawParentBackground(Self.Handle, Canvas.Handle, Details, False);
StyleServices.DrawElement(Canvas.Handle, Details, ClientRect);
end;

这就是结果

enter image description here

关于Delphi XE2风格绘画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com