private void delBtn_Click(object sender, EventArgs e) { //有产品时才响应删除 if (productCombo.Items.Count > 0) { //先提示用户是否确认删除操作 DialogResult res = MessageBox.Show("您确定要删除该产品吗?", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (res == DialogResult.OK) { int index = productCombo.SelectedIndex; productCombo.Items.RemoveAt(index); productNameList.RemoveAt(index); //包含则从文件中删除 iniFileOp.ClearSection(curProductName); //并及时更新显示 if (productCombo.Items.Count > 0) { productCombo.SelectedIndex = 0; curProductName = productCombo.SelectedItem.ToString(); } else { productCombo.Items.Clear(); productCombo.Text = ""; curProductName = ""; } } } }