示例我有一个组合框,其中有3个列表:entry、exit和transfer,还有一个从0开始的名为:txtTotal的numericupdown当我选择进入或退出时,应该显示错误丢失总数,但如果选择转移,即使是0或其他数字,也应该允许您继续
如果您想在选择进入或退出时显示错误丢失总数,并允许您在选择转移时继续,即使txttotal显示0或其他数字,您可以参考以下代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Entry");
comboBox1.Items.Add("Exit");
comboBox1.Items.Add("Transfer");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "Entry" || comboBox1.Text == "Exit")
{
MessageBox.Show("Error missing total is " + txtTotal.Text);
}
if (comboBox1.Text == "Transfer")
{
// You should replace this code with what you want to do
string FileToRead = "the path of txt file";
string[] lines = File.ReadAllLines(FileToRead);
foreach (string str in lines)
{
if (str == "2")
{
txtTotal.UpButton();
}
}
}
}
}