Delphi TSpeedButton losing glyph when disabled

356 Views Asked by At

I have a TSpeedButton that should have 2 main statuses, one for the pressed status (down) and one when it's up. What i want to achieve is to display an icon of the glyph bitmap also when the button is not pressed and not enabled.

The bitmap contains 3 icons, one for the pressed button, one for the not pressed and one for the not pressed when the control is disabled.

1

There are 1 best solutions below

0
Issam On

Try this : The next sample code consider that you have loaded your icons/Bitmaps inside TimageList .

procedure SpeedButton1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
SpeedButton1.Glyph:=nil;
ImageList1.GetBitmap(0,SpeedButton1.Glyph);
End;

procedure SpeedButton1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
SpeedButton1.Glyph:=nil;
ImageList1.GetBitmap(1,SpeedButton1.Glyph);
end;

For the Third status you can do the same with SpeedButton1MouseLeave procedure .

procedure SpeedButton1MouseLeave(Sender: TObject);
begin
if not SpeedButton1.Enabled then
begin
    SpeedButton1.Glyph:=nil;
    ImageList1.GetBitmap(2,SpeedButton1.Glyph);
end;