我正在做一个井字游戏,我正在尝试添加一个组合框,它会根据人们现在选择的内容更改应用程序背景我有夏天、 Spring 、秋天、冬天,图像在bin/debug 文件夹我怎样才能让它工作我不知道从哪里开始而且教程有点困惑。你能帮帮我吗
你问的不是很清楚。假设您的 bin\Debug 文件夹中有名称为“spring.png”等的位图文件,这应该可以工作:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
comboBox1.Items.AddRange(new string[] { "Spring", "Summer", "Fall", "Winter" });
comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
string folder = Application.StartupPath;
string theme = (string)comboBox1.Items[comboBox1.SelectedIndex];
string path = System.IO.Path.Combine(folder, theme + ".png");
Image newImage = new Bitmap(path);
if (this.BackgroundImage != null) this.BackgroundImage.Dispose();
this.BackgroundImage = newImage;
}
}
我是一名优秀的程序员,十分优秀!