Search code examples
delphithemesdelphi-12-athens

How to get the images of a TDBNavigator with a TStyle theme applied to it?


I'm using Delphi 12 Athens, and have a custom style applied to my application.

I would like to get the images of a TDBNavigator to assign them to a specific TSpeedButton.

Is this possible?

I've try this, but the images returned are the defaults for the component:

ic  := TImageList.Create(self);
nav := THackDBNavigator.Create(self);
     
ic.Assign(THackDBNavigator( nav ).GetButtonImageList);
SpeedButtonFirst.Images     := ic;
SpeedButtonFirst.ImageIndex := Integer(nbFirst);

Solution

  • There is no direct way to get the images from a style but you can use DrawElement:

    var
      r: TRect;
    begin
      FreeAndNil(SpeedButtonFirst.Glyph);
      SpeedButtonFirst.Glyph := TBitmap.Create(24, 24);
      r := Rect(0, 0, SpeedButtonFirst.Glyph.Width, 
        SpeedButtonFirst.Glyph.Height);
      TStyleManager.ActiveStyle.DrawElement(
        SpeedButtonFirst.Glyph.Canvas.Handle, 
        TStyleManager.ActiveStyle.GetElementDetails(tdnbFirstPressed), 
        r, r);
    end;
    

    Update: DrawElement is drawing already transparent. Check in unit Vcl.StyleAPI in method TSeBitmapObject.DrawNormal in line 5499 if DrawBitmap.Image.Transparent is set