如果用户在 ComboBox 上选择一个字符串,你如何让它显示?

If user picks a string on a ComboBox how do you get it to display?

我正在尝试获取用户输入以选择颜色。我用过 ComboBox.

如何让程序查看用户所做的选择以便在 MessageBox 中显示?我正在考虑使用 if 语句。

string red;
string blue;
string white;
string green;
string purple;
string yellow;
string colour = "";

使用 SelectedIndexChanged 事件处理程序。

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
   MessageBox.Show(comboBox1.SelectedItem.ToString());
}