The Image property of a Button control is used to set a button background as an image.
The Image property needs an Image object.
The Image class has a static method called FromFile that takes an image file name with full path and creates an Image object.
You can also align image and text. The ImageAlign and TextAlign properties of Button are used for this purpose.
The following code snippet sets an image as a button background.
// Assign an image to the button.
button1.Image = Image.FromFile(@"C:\Images\csharp.jpg");
// Align the image and text on the button.
button1.ImageAlign = ContentAlignment.MiddleRight;
button1.TextAlign = ContentAlignment.MiddleLeft;
// Give the button a flat appearance.
button1.FlatStyle = FlatStyle.Flat;
Leave a Comment