1

i'm trying to paint vcl style background from TSeStyleFont like in Bitmap Style Designer .. is there any way to draw the background ?

enter image description here

i have make a try : - draw the object first in a bitmap using DrawElement . - than copy current bitmap to a nother clean bitmap using 'Bitmap.Canvas.CopyRect' the problem is that : this methode does not work correctly with objects that has Glyph such as 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;
4

1 回答 1

6

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

在此处输入图像描述

于 2013-05-09T21:09:10.377 回答