【问题标题】:Increase font size of ListItem in Combo box that comes as suggested in dropdown增加下拉列表中建议的组合框中 ListItem 的字体大小
【发布时间】:2020-12-09 07:30:20
【问题描述】:
我在 Visual Studio 中使用 C# 创建桌面应用程序时使用组合框,现在当我运行应用程序并单击下拉按钮列表元素时,我将字体大小增加到“20”,字体大小也增加了。
没关系。但是,当我在组合框中写一些东西时,它会给出如下图所示的建议。
我,也想增加这个建议列表的字体大小,我已将“AutoCompleteMode”属性设置为“建议”。有人可以帮我解决这个问题吗?
【问题讨论】:
标签:
c#
visual-studio
combobox
dropdown
【解决方案1】:
显示的自动完成文本的字体是固定的。没有对应的属性可以设置。
一种解决方法是您可以创建一个自定义控件并将建议下拉菜单替换为自定义列表框。
public Form1()
{
InitializeComponent();
comboBox1.Size = new Size(120, 30);
listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
}
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Text = listBox.Text;
listBox.Visible = false;
}
ListBox listBox = new ListBox();
// event triggered when the user enters text
private void comboBox1_TextUpdate(object sender, EventArgs e)
{
// set the font of listbox to be consistent with combobox
listBox.Font = comboBox1.Font;
// add listbox below combobox
listBox.Location = new Point(comboBox1.Location.X, comboBox1.Location.Y + comboBox1.Height);
// filter suggest items
listBox.Items.Clear();
foreach (string item in comboBox1.Items)
{
if (item.StartsWith(comboBox1.Text) && comboBox1.Text != string.Empty)
{
listBox.Items.Add(item);
}
}
listBox.Visible = listBox.Items.Count > 0;
this.Controls.Add(listBox);
}
测试结果:
【解决方案2】:
这些实际上是您可以独立配置的两个区域。根据这篇 MSDN 文章,
更改设置:
- 转到工具 - 选项 - 环境 - 字体和颜色
- 在显示设置下:选择语句完成或编辑器工具提示(用于参数信息和快速提示)
- 更改字体或字号