Reputation: 98
I'm trying to set the image of a button programmatically in my Form_Load event, but for some reason it won't work, can someone check this code for me really quick, please?
private void MainForm_Load(object sender, EventArgs e)
{
gameBTN1.Text = "";
Image icon = Image.FromFile(GameInfo.SampleGame.GameImage);
gameBTN1.Image = icon;
}
public class SampleGame
{
public static string Name = "Sample";
public static string Hash = "";
public static string GameImage = @"GameIMG/SampleGame.jpg";
}
Upvotes: 2
Views: 3536
Reputation: 815
check your flatstyle :)
If the FlatStyle property is set to FlatStyle.System, any images assigned to the Image property are not displayed.
use instead:
// Give the button a flat appearance.
button1.FlatStyle = FlatStyle.Flat;
Upvotes: 4