C# ComboBox 下拉框自动匹配笔记
using System;
using System.Drawing;
using System.Windows.Forms;
partial class ComboBoxExample : Form
{
public static void Main()
{
Application.Run(new ComboBoxExample());
}
}
partial class ComboBoxExample
{
private ComboBox GradeCbox;
private Label TipsLbl;
public ComboBoxExample()
{
this.Size = new Size(500, 380);
this.StartPosition = FormStartPosition.CenterScreen;
GradeCbox = new ComboBox();
GradeCbox.Size = new Size(400, 60);
GradeCbox.Location = new Point((500-400) / 2, (380-60) / 2);
GradeCbox.Font = new Font("楷体", 12, FontStyle.Bold);
GradeCbox.DataSource = new string[]
{
"AutoCompleteMode.Append",
"AutoCompleteMode.None",
"AutoCompleteMode.Suggest",
"AutoCompleteMode.SuggestAppend",
"AutoCompleteSource.AllSystemSource",
"AutoCompleteSource.AllUrl",
"AutoCompleteSource.CustomSource",
"AutoCompleteSource.FileSystem",
"AutoCompleteSource.FileSystemDirectories",
"AutoCompleteSource.HistoryList",
"AutoCompleteSource.ListItems",
"AutoCompleteSource.None",
"AutoCompleteSource.RecentlyUsedList"
};
// 指定自动匹配数据源
// GradeCbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
// GradeCbox.AutoCompleteCustomSource.AddRange(new string[] {"AAA", "BBB", "ABC", "BCA"});
// 指定自己的数据项为自动匹配的数据源
GradeCbox.AutoCompleteSource = AutoCompleteSource.ListItems;
GradeCbox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
GradeCbox.SelectedIndexChanged += new EventHandler(GradeCboxSelectIndexChanged);
// GradeCbox.DropDownStyle = ComboBoxStyle.DropDownList;
this.Controls.Add(GradeCbox);
TipsLbl = new Label();
TipsLbl.Text = "未选中";
TipsLbl.Size = new Size(200, 60);
TipsLbl.Location = new Point((500-200) / 2, ((380-60) / 2 - 60) / 2);
TipsLbl.Font = new Font("楷体", 12, FontStyle.Bold);
this.Controls.Add(TipsLbl);
}
private void GradeCboxSelectIndexChanged(object sender, EventArgs e)
{
if (GradeCbox.SelectedIndex != -1)
{
TipsLbl.Text = GradeCbox.Items.ToString();
}
}
} 学习一下 6666,我们招人哦,要不要考虑下🤭 nappywu 发表于 2021-6-23 12:42
6666,我们招人哦,要不要考虑下🤭
干什么的?
页:
[1]