first, I am sorry if my English is bad. When I work in winform C#, I want to add an image to the button and set it before the text. However, it is too big and I want to scale it smaller to make the button better
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
initButton();
}
private void initButton()
{
string path = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"Images",
"folder.png");
int square = buttonWithImage.Height - 4;
Image resizedImage =
new Bitmap(
Bitmap.FromFile(path),
new Size(square, square));
buttonWithImage.Image = resizedImage;
buttonWithImage.ImageAlign = ContentAlignment.MiddleLeft;
buttonWithImage.TextAlign = ContentAlignment.MiddleRight;
}
}
One way of making sure that the image file can be located.