问题描述
我在Visual Studio中使用C#创建桌面应用程序时正在使用组合框,我将字体大小增加到"20".现在,当我运行该应用程序并单击下拉按钮时,列表元素的字体大小也增加了.
I am using Combo box while creating Desktop Application using C# in Visual Studio, I increased the font size to "20" now when I run the application and click the dropdown button list elements font-size also increased.
很好.但是,当我在组合框中写一些内容时,它会给出一些建议,如下图所示.
That's fine. But, when I write something in the combo box it gives suggestions as shown in the picture below.
我也想增加此建议列表的字体大小,因此我已经将"AutoCompleteMode"设置为属性设置为建议".有人可以帮我吗?
I, also want to increase the font size of this suggestion list, I have set "AutoCompleteMode" property set to "suggest". Is anybody can help me with this?
推荐答案
显示的自动完成文本的字体是固定的.没有相应的属性可以设置.
The font of the auto-complete text presented is fixed. There is no corresponding properties to set it.
一种解决方法是,您可以创建一个自定义控件,并用自定义列表框替换建议"下拉列表.
A workaround is that you can create a custom control and replace the suggest-drop-down with custom listbox.
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);
}
测试结果:
这篇关于根据下拉列表中的建议,增加“组合"框中的ListItem的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!