【问题标题】:painting background from TSeStyleFont来自 TSeStyleFont 的绘画背景
【发布时间】:2013-05-09 19:52:00
【问题描述】:

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

我试了一下: - 首先使用 DrawElement 在位图中绘制对象。 - 比使用 'Bitmap.Canvas.CopyRect' 将当前位图复制到另一个干净的位图,问题在于:此方法不适用于具有 Glyph 的对象,例如 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;

【问题讨论】:

  • 是否要绘制按钮的背景?
  • 这个问题充其量是令人困惑的,请改写问题
  • > 是否要绘制按钮的背景?是的,像这样。事实上,我已经尝试过: - 首先使用 DrawElement 在位图中绘制对象。 - 比使用 'Bitmap.Canvas.CopyRect' 将当前位图复制到另一个干净的位图,问题在于:此方法不适用于具有 Glyph 的对象,例如 CheckBox ...

标签: delphi delphi-xe2 vcl-styles


【解决方案1】:

如果您想绘制按钮的背景,您必须使用 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;

如果你想绘制没有角的背景,你可以像这样调整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;

【讨论】:

  • 和答案样本有什么区别?
  • 背景是一个完整的矩形(没有角)
猜你喜欢
  • 2011-05-12
  • 1970-01-01
  • 2012-09-27
  • 2020-10-10
  • 1970-01-01
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多