gpt4 book ai didi

c# - Combobox如何让所选项目显示主题

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:53 25 4
gpt4 key购买 nike

我正在做一个井字游戏,我正在尝试添加一个组合框,它会根据人们现在选择的内容更改应用程序背景我有夏天、 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;
}
}

关于c# - Combobox如何让所选项目显示主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com