ser*_*ads 3 c# size combobox winforms
我正在开发一种触摸屏设备的应用程序.为了方便用户,我需要改变组合框的大小.
我检查了很多东西,包括DrawItemEventHandler和MeasureItemEventHandler,但它没有按我的意愿工作.
基本上我想在不触及字体大小的情况下改变组合框的高度.当我更改组合框的字体大小时,它看起来像图像的左侧.如何设置看起来像图像右侧的组合框?

顺便说一句,不知道它是否有效解决方案,我不是使用数组字符串.我绑定的数据就像.
combobox.DisplayMember = "Name";
combobox.ValueMember = "ID";
combobox.DataSource = new BindingSource { DataSource = datalist };
Run Code Online (Sandbox Code Playgroud)
提前致谢.
有了TaW解决方案,我设法按照自己的意愿设置项目.当组合框项目没有下降时,我唯一无法在中间设置文本.如何将此文本位置设置为中心?

您可以设置ItemHeight属性,然后在DrawItem事件中自己绘制项目.
不是很难,搜索'ownerdraw'和'combobox'.代码项目有一个例子
这是一个最小版本,从上面的链接中提取:
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0) return;
Font f = comboBox1.Font;
int yOffset = 10;
if ((e.State & DrawItemState.Focus) == 0)
{
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), f, Brushes.Black,
new Point(e.Bounds.X, e.Bounds.Y + yOffset));
}
else
{
e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), f, Brushes.White,
new Point(e.Bounds.X, e.Bounds.Y + yOffset));
}
Run Code Online (Sandbox Code Playgroud)
}
您还必须设置DropDownStyle为DropDownList以使突出显示起作用,您需要设置DrawMode为OwnerDrawFixed.(或者OwnerDrawVariable,如果你想对某些主题有不同的高度..)