TAdvSmoothExpanderButton Picture: how to draw it?

I have a form that "generates" TAdvSmoothExpanderButton buttons in a TAdvSmoothExpanderButtonPanel.
The number of buttons depends on a variable, so i create the buttons at runtime, using the panel-<Buttons->Add() method.

Each button needs its own picture, which is drawn at runtime. I'm unable to draw my bitmap in the button picture.

My old code, working with TLMDSpeedButtons, was:


    ...
        But->Glyph->SetSize(PaccBrowser->Bitmap->Width, PaccBrowser->Bitmap->Height);
        But->Glyph->Canvas->Draw(0,0,PaccBrowser->Bitmap);
    ...


where PaccBrowser is a GraphicComponent containing the final bitmap to be used as button icon.

i tried with this code:


            bp->Picture->SetSize(PaccBrowser->Bitmap->Width, PaccBrowser->Bitmap->Height);
            A_TRect.Left = 0;
            A_TRect.Top = 0;
            A_TRect.Right = PaccBrowser->Bitmap->Width;
            A_TRect.Bottom = PaccBrowser->Bitmap->Height;
            bp->Picture->Draw(PaccBrowser->Bitmap->Canvas,A_TRect);


but i see nothing, and "watching" the Picture property in the debugger it seems still not initialized.

What should i do to draw the bitmap from my PaccBrowser to a TAdvSmoothExpanderButton picture?

Thanks

Hello Fabio,

I think you should not paint the buttons yourself, but just add them to the panel and eventually assign the bitmap to the "Picture" property, that's it.

I took as example base the Delphi code of the demo in "Samples\AdvSmoothPanel\Demo2\UDemo.pas"
and tried a little and found this to be working:

var
  I: Integer;
  ARect : TRect;
  PaccBrowser: TBitmap;
begin
 ...
  AdvSmoothExpanderButtonPanel1.ButtonHeight := 32;

  AdvSmoothExpanderButtonPanel1.ButtonWidth := 32;

  PaccBrowser := TBitmap.Create;
  PaccBrowser.Height := AdvSmoothExpanderButtonPanel1.ButtonHeight;
  PaccBrowser.Width := AdvSmoothExpanderButtonPanel1.ButtonWidth;
  ARect.Left := 0;
  ARect.Top := 0;
  ARect.Right := PaccBrowser.Width;
  ARect.Bottom := PaccBrowser.Height;
  ...
  try
    for I := 0 to 5 do begin
      with AdvSmoothExpanderButtonPanel1.Buttons.Add do begin
        BevelColor := clBlack;

        Randomize;
        // Fill bitmap with random color - for testing
        PaccBrowser.Canvas.Brush.Color := RGB(Random(255), Random(255), Random(255));
        PaccBrowser.Canvas.FillRect(ARect);
        // Assign the bitmap to the Picture -> done
        Picture.Assign(PaccBrowser);
      end;
    end;
  finally
    PaccBrowser.Free;
  end;
...
end;



Maybe this helps.

Regards,
Tobias

Thanks!!!
It works.
I did'nt think at the assign method, maybe 'cause my long story habits with the bitblt and draw methods.
Anyway, i'd like to know how to initialize the button picture by code, in case i have to draw in it directly.
Thanks again.

P.S. I add the buttons to the panels with the Add method, i just needed a way to change the button Picture property at runtime. Drawing the entire button on the panel is the last thing i want to do :) Sorry for not have been clear.