Question

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;
Was it helpful?

Solution

If you want draw the background of the buttons you must use the StyleServices.DrawElement method passing the proper TThemedButton part.

Try this sample

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

If you want draw the background without corners, you can adjust the bounds of the TRect like so

  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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top