[英]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? 我试图在我的Form_Load事件中以编程方式设置按钮的图像,但由于某种原因它不起作用,有人可以非常快地检查这段代码吗?
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. 如果FlatStyle属性设置为FlatStyle.System,则不会显示分配给Image属性的任何图像。
use instead: 改为使用:
// Give the button a flat appearance.
button1.FlatStyle = FlatStyle.Flat;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.