Reputation: 159
I need to display an image in a button, so that it is visually easier for the user to know what the button is for instead of reading its text.
as far as I can tell TBitBtn
and TSpeedButton
are buttons that can show an image, but I do not know anything about it and I would like to know if it is possible to have a .JPG or .PNG file and load that image into the button so that it displays it.
Upvotes: 1
Views: 4098
Reputation: 11
Yes it is possible. The background color of the TBitBtn type button is transparent by default in some cases. Create a PNG image with a transparent background. Place a TImage component on the form. Load the PNG image into the Image property of the TImage component. Place the TImage component with the selected image in the place on the form where the TBitBtn button will be. Place a TBitBtn button on the image. That will be nice push button.
Upvotes: 1
Reputation: 598434
TBitBtn
and TSpeedButton
only support BMP images, not JPG/PNG. You would have to convert the JPG/PNG images to BMP (which can be done in code by loading the images into TJPEGImage
/TPNGImage
first, and then Assign()
them to the button's Glyph
, which is a TBitmap
).
In modern Delphi versions, TButton
has an Images
property that you can assign any TCustomImageList
to, and you can add PNG images to a standard TImageList
, or use a 3rd party PNG ImageList.
Otherwise, you can create your own owner-drawn button to draw JPG/PNG images directly. Derive from TButton
and override its CreateParams()
method to enable the BS_OWNERDRAW
style, and then handle the WM_DRAWITEM
message to draw the button however you want (this is what TBitBtn
does).
Upvotes: 8
Reputation: 6184
No, you cannot assign a file to any of them. If you don't know a control, look up the manual to it: http://docwiki.embarcadero.com/Libraries/Tokyo/en/Vcl.Buttons.TBitBtn and http://docwiki.embarcadero.com/Libraries/Tokyo/en/Vcl.Buttons.TSpeedButton
You have to do it indirectly: loading the file into a TBitmap, then assigning that to the button's Glyph property - the manual gives you one example thru http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/TBitBtnLayout_(Delphi)
Upvotes: 2