delphi - TSeStyleFont 的绘画背景

标签 delphi delphi-xe2 vcl-styles

我正在尝试从 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/

相关文章:

Delphi读取溢出标志

delphi - 如何阻止 TRadioButton 对方向键使用react?

delphi - 启用 vcl 样式后如何使用 native 进度条?

delphi - 使用 VCL 样式时覆盖某些 TBitButton 的样式

c# - 将C#代码转换为Delphi,SafeWaitHandle等同于什么?

multithreading - 从delphi中的线程中止整个应用程序

delphi - 如何在delphi中为azure blob存储生成MD5?

delphi - 如何加载JPE图像文件?

德尔福XE2 64位: inline asm in GraphicEx

Delphi 外观无闪烁