/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Text = "ComboBox控件使用示例";
label1.Text = "Simple";
label1.AutoSize = true;//自动尺寸
label2.Text = "Dropdown";//下拉
label2.AutoSize = true;
label3.Text = "DropdownList";
label3.AutoSize = true;
label4.Text = "被选中的项";
label4.AutoSize = true;
textBox1.Text = "";
string[] strCountry = {"中国","朝鲜","越南","老挝","缅甸 ","印度","尼泊尔","俄罗斯"};
for(int i = 0; i < strCountry.Length;i++)//条件
{
comboBox1.Items.Add(strCountry[i]);
comboBox2.Items.Add(strCountry[i]);
comboBox3.Items.Add(strCountry[i]);
}
comboBox1.DropDownStyle = ComboBoxStyle.Simple;
comboBox2.DropDownStyle = ComboBoxStyle.DropDown;
comboBox3.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(comboBox1.SelectedIndex > -1)//如果被选择的大于-1就被选上
{
textBox1.Text += comboBox1.Text + ";";//直接在后面连
label4.Text = "comboBox1键盘选择的选项";
}
}
private void comboBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)Keys.Enter)//e消息,按下去的键,==判断,打了回车键之后作什么
{
textBox1.Text += comboBox1.Text + ";";
label4.Text = "comboBox1键盘输入的选项";
}
}
}
}
阅读(1837) | 评论(0) | 转发(0) |