ComboBox 在C#中做窗体做下拉菜单是一个好的选择具体用法下:
(1)创建一个ComboBoxItem类如下:
public class ComboBoxItem
{
private string _text = null;
private object _value = null;
public string Text { get { return this._text; } set { this._text = value; } }
public object Value { get { return this._value; } set { this._value = value; } }
public override string ToString()
{
return this._text;
}
}
(2)控件的初始化:
public Form1()
{
InitializeComponent();
ComboBoxItem cb1 = new ComboBoxItem();
cb1.Text = "用户";
cb1.Value = "用户";
comboBox1.Items.Add(cb1);
ComboBoxItem cb2 = new ComboBoxItem();
cb2.Text = "管理员";
cb2.Value = "管理员";
comboBox1.Items.Add(cb2);
}
获取控件的内容:
Uqxian = Convert.ToString(comboBox1.Text);
if (Uqxian == "管理员")
MessageBox.Show("请选择权限", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);