简体   繁体   中英

Programmatically setting button image

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";
}

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM