资源简介
vs2008演示演示ComboBox下拉列表控件的使用实例
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace UseComboBox
{
public partial class Form1 : Form
{
public Form1( )
{
InitializeComponent( );
}
private void Form1_Load(object sender EventArgs e)
{
//初始化可选项为“00”到“10”,
for (int i = 0; i < 10; i++)
{
this.cmbItems.Items.Add(i.ToString(“D2“));
}
//绑定SelectedIndexChanged事件
this.cmbItems.SelectedIndexChanged += new EventHandler(cmbItems_SelectedIndexChanged);
//默认选中第1项(索引为0)
this.cmbItems.SelectedIndex = 0;
}
void cmbItems_SelectedIndexChanged(object sender EventArgs e)
{
//生成提示文本,并显示到lbHint
string str = “当前选中:Index=“ + this.cmbItems.SelectedIndex.ToString( )
+ “ value=‘“ + (string)this.cmbItems.SelectedItem + “‘“;
this.lbHint.Text = str;
}
private void btnAdd_Click(object sender EventArgs e)
{
//去除输入框中的前后空白,然后添加到cmbItems
string str = this.tbNewItem.Text.Trim( );
if (!string.IsNullOrEmpty(str))
this.cmbItems.Items.Add(str);
}
private void btnDelete_Click(object sender EventArgs e)
{
//如果有选中删除,否则提示
if (this.cmbItems.SelectedIndex >= 0)
this.cmbItems.Items.RemoveAt(this.cmbItems.SelectedIndex);
else
MessageBox.Show(“没有任何选中项,请先选中!“);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10240 2009-01-16 13:51 UseComboBox\UseComboBox\bin\Debug\UseComboBox.exe
文件 22016 2009-01-16 13:51 UseComboBox\UseComboBox\bin\Debug\UseComboBox.pdb
文件 14328 2009-01-16 13:51 UseComboBox\UseComboBox\bin\Debug\UseComboBox.vshost.exe
文件 490 2007-07-21 01:33 UseComboBox\UseComboBox\bin\Debug\UseComboBox.vshost.exe.manifest
文件 1901 2007-09-11 19:44 UseComboBox\UseComboBox\Form1.cs
文件 5018 2007-09-11 19:41 UseComboBox\UseComboBox\Form1.Designer.cs
文件 5814 2007-09-11 19:39 UseComboBox\UseComboBox\Form1.resx
文件 896 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\UseComboBox.csproj.FileListAbsolute.txt
文件 847 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\UseComboBox.csproj.GenerateResource.Cache
文件 10240 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\UseComboBox.exe
文件 180 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\UseComboBox.Form1.resources
文件 22016 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\UseComboBox.pdb
文件 180 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\UseComboBox.Properties.Resources.resources
文件 473 2007-09-11 18:32 UseComboBox\UseComboBox\Program.cs
文件 1194 2007-09-11 18:32 UseComboBox\UseComboBox\Properties\AssemblyInfo.cs
文件 2846 2008-03-08 11:56 UseComboBox\UseComboBox\Properties\Resources.Designer.cs
文件 5612 2007-09-11 18:32 UseComboBox\UseComboBox\Properties\Resources.resx
文件 1109 2008-03-08 11:56 UseComboBox\UseComboBox\Properties\Settings.Designer.cs
文件 249 2007-09-11 18:32 UseComboBox\UseComboBox\Properties\Settings.settings
文件 3437 2008-03-08 11:56 UseComboBox\UseComboBox\UseComboBox.csproj
文件 923 2008-03-08 11:56 UseComboBox\UseComboBox.sln
..A..H. 17920 2009-01-16 13:52 UseComboBox\UseComboBox.suo
目录 0 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug\TempPE
目录 0 2009-01-16 13:51 UseComboBox\UseComboBox\bin\Debug
目录 0 2009-01-16 13:51 UseComboBox\UseComboBox\obj\Debug
目录 0 2009-01-16 13:51 UseComboBox\UseComboBox\bin
目录 0 2009-01-16 13:51 UseComboBox\UseComboBox\obj
目录 0 2009-01-12 14:11 UseComboBox\UseComboBox\Properties
目录 0 2009-01-16 13:51 UseComboBox\UseComboBox
目录 0 2009-01-12 14:11 UseComboBox
............此处省略3个文件信息
- 上一篇:三层电梯控制器verilog
- 下一篇:毫米波通信
评论
共有 条评论