gpt4 book ai didi

delphi - TSeStyleFont 的绘画背景

转载 作者:行者123 更新时间:2023-12-03 05:24:31 33 4
gpt4 key购买 nike

我正在尝试从 TSeStyleFont 绘制 vcl 样式背景,就像在位图样式设计器中一样。有什么办法可以绘制背景吗?

enter image description here

我已经尝试过:- 首先使用 DrawElement 在位图中绘制对象。- 与使用“Bitmap.Canvas.CopyRect”将当前位图复制到另一个干净的位图相比,问题在于:此方法无法正确处理具有字形(例如 CheckBox)的对象...

  var
bmp, bmp2: TBitmap;
Details: TThemedElementDetails;
R, Rn: TRect;
begin
bmp := TBitmap.Create;
bmp2 := TBitmap.Create;
R := Rect(0, 0, 120, 20);
Rn := Rect(0 + 4, 0 + 4, 120 - 4, 20 - 4);
bmp.SetSize(120, 20);
bmp2.SetSize(120, 20);
Details := StyleServices.GetElementDetails(TThemedButton.tbPushButtonHot);
StyleServices.DrawElement(bmp.Canvas.Handle, Details, R);
bmp2.Canvas.CopyRect(R, bmp.Canvas, Rn);
Canvas.Draw(10, 10, bmp2);
bmp.Free;
bmp2.Free;

end;

最佳答案

如果你想绘制按钮的背景,你必须使用StyleServices.DrawElement方法传递正确的 TThemedButton部分。

尝试这个示例

uses
Vcl.Styles,
Vcl.Themes;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
Details : TThemedElementDetails;
begin
Details := StyleServices.GetElementDetails(tbPushButtonPressed);
StyleServices.DrawElement(PaintBox1.Canvas.Handle, Details, PaintBox1.ClientRect);

Details := StyleServices.GetElementDetails(tbPushButtonNormal);
StyleServices.DrawElement(PaintBox2.Canvas.Handle, Details, PaintBox2.ClientRect);
end;

enter image description here

如果你想绘制没有角的背景,你可以像这样调整TRect的边界

  Details : TThemedElementDetails;
LRect : TRect;
begin
LRect:=PaintBox1.ClientRect;
LRect.Inflate(3,3);

Details := StyleServices.GetElementDetails(tbPushButtonPressed);
StyleServices.DrawElement(PaintBox1.Canvas.Handle, Details, LRect);

LRect:=PaintBox2.ClientRect;
LRect.Inflate(3,3);
Details := StyleServices.GetElementDetails(tbPushButtonNormal);
StyleServices.DrawElement(PaintBox2.Canvas.Handle, Details, LRect);
end;

enter image description here

关于delphi - TSeStyleFont 的绘画背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16469976/

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