我是C#的新手,我试图在combobox
项更改后向用户提示消息,但即使combobox
项已更改,以下代码也不起作用。
namespace NormingPointTagProgrammer
{
public partial class normingPointTagProgrammer : Form
{
public normingPointTagProgrammer()
{
InitializeComponent();
// User Message to start the tag programming
MessageBox.Show("To Read the data programmed in a Tag, Click on READ Button\n" +
"To Write data into the tag, \n" +
"Please select the Data Format, under DATA TO PROGRAMMER frame.");
}
private void dataFormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
// When the user has decided to program the tag. Check the Data format selected by the user, and ask the user to
// enter required fields based on the format selected.
if (datFormatcomboBox.Text == "RSO")
{
MessageBox.Show("Within DATA TO PROGRAMMER frame, under RSO DATA from DataBase Enter the following fields: \n" +
"Region (1-254),\n" +
"Segment (1-255),\n" +
"Offset (0 to 6553.5) and \n" +
"select Type dropdown Field, Under");
}
else if (datFormatcomboBox.Text == "INDEX")
{
MessageBox.Show("Within DATA TO PROGRAMMER frame, under INDEX DATA from DataBase Enter the following fields: \n" +
"Region (255) and \n" +
"Index (1-65535) ");
}
else if (string.IsNullOrWhiteSpace(datFormatcomboBox.Text))
{
MessageBox.Show("Please select the Data Format, under DATA TO PROGRAMMER frame.");
}
else
{
MessageBox.Show("Required fields not entered by the user.\n" +
"Please enter the data to be programmed based on the Data Format selected");
}
}
}
}
答案 0 :(得分:0)
验证您的活动是否正在订阅,简写将使用以下内容,例如
ComboBoxChanged += dataFormatComboBox_SelectedIndexChanged();
或者,
ComboBoxChanged += new EventHandler(dataFormatComboBox_SelectedIndexChanged);
// This will be called whenever the ComboBox changes:
private void dataFormatComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
//Your datFormatcomboBox.Text logic here.
}
基本上,无论传递给ComboBoxChanged,使用e
来获取ComboBox文本的输入。
此处提供更多信息:https://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
希望有所帮助!