给定以下代码
namespace WindowsFormsApplication1
{
public class Form1 : Form
{
public Form1()
{
comboBox1 = new System.Windows.Forms.ComboBox();
comboBox1.Items.AddRange(new object[] {
"Item 1",
"Item 2",
"Item 3"});
comboBox1.Location = new System.Drawing.Point(93, 103);
comboBox1.Name = "comboBox1";
comboBox1.Size = new System.Drawing.Size(121, 21);
comboBox1.Text = "Item 1"; // **line 1**
ClientSize = new System.Drawing.Size(284, 262);
Controls.Add(this.comboBox1);
Name = "Form1";
Text = "Form1";
comboBox1.Text = "Nanu"; // **line 2**
}
private ComboBox comboBox1;
}
}
我希望我的 ComboBox 显示“Nanu”(DropDownStyle.DropDown),但它显示“Item 1”。省略该行可以comboBox1.Text = "Item 1";
解决此问题。放入OnShowncomboBox1.Text = "Nanu";
事件处理程序也修复了“错误”。
为什么是这样?