Mega Code Archive

 
Categories / Delphi / VCL
 

Using an icon as the glyph in a tspeedbutton

Question: Is it possible to use an icon as the Glyph in a TSpeedButton component? Answer: The following example demonstrates painting an Icon's image onto a SpeedButton's Glyph. Example: uses ShellApi; procedure TForm1.FormShow(Sender: TObject); var Icon: TIcon; begin Icon := TIcon.Create; Icon.Handle := ExtractIcon(0, 'C:\WINDOWS\NOTEPAD.EXE', 1); SpeedButton1.Glyph.Width := Icon.Width; SpeedButton1.Glyph.Height := Icon.Height; SpeedButton1.Glyph.Canvas.Draw(0, 0, Icon); Icon.Free; end;