How to use images in imagelist as background images for buttons [C#]

Shaitan00

Junior Contributor
Joined
Aug 11, 2003
Messages
358
Location
Hell
Okay - as many people suggested I created an imagelist and added my 3 pictures to it (as shown in the code below).
Problem I am having now, no clue how to get these now added images as background images to my buttons.
(...if only ImageButtons existed...)

Specifically - I have 3 buttons (btnStart, btnPause, btnStop) and I want to display the corresponding START, PAUSE, STOP images as their background.
But I have no clue how to a) use the imagelist images I just added and b) set a background image to a button via code.

Code:
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Button btnPause;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.ImageList imglst;
...

// Add Images to ImageList and display on buttons
imglst.Images.Add(Image.FromFile("C:\\img\\Play.png"));
imglst.Images.Add(Image.FromFile("C:\\img\\Pause.png"));
imglst.Images.Add(Image.FromFile("C:\\img\\Stop.png"));
btnStart.?
btnPause.?
btnStop.?

As you can see, I loaded my images... now what? How do I use them? How to I set them as the background image for the buttons?
Thanks - I know I am asking for a lot but can't see to figure this part out, any help/hints would be appreciated.
 
Okay - I found a bit of code that worked great but I have one last question...
(FYI: bit of code: myButton.BackgroundImage = myImageList.Images(0))

The size of the .PNG is a lot smaller then that of the actual button, currently there are like 6 copies of the START/PAUSE/STOP images in each button.

I need to FIT/FILL/STRETCH the .PNG to fix the size of the button so there is only ONE start/pause/stop image per button (as it should be logically).

Any clues?
 
Back
Top