我有这个界面:

我想要做的是将左侧的名称ListBox与右侧的网格对齐或隔开,以便每个名称与每个网格行内联。
我确实试过这个:
lstNames.ItemHeight = 15;
但这并不影响它。注意:Mylistbox是使用数据库动态创建和填充的。
关于如何实现这一目标的任何提示?
我有这个界面:

我想要做的是将左侧的名称ListBox与右侧的网格对齐或隔开,以便每个名称与每个网格行内联。
我确实试过这个:
lstNames.ItemHeight = 15;
但这并不影响它。注意:Mylistbox是使用数据库动态创建和填充的。
关于如何实现这一目标的任何提示?
您必须将DrawMode属性更改OwnerDrawFixed为使用 custom ItemHeight。
当你使用DrawMode.OwnerDrawFixed你必须paint/draw items "manually".
引用Max自此Stackoverflow发布的Combobox 外观
public class ComboBoxEx : ComboBox
{
public ComboBoxEx()
{
base.DropDownStyle = ComboBoxStyle.DropDownList;
base.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
if(e.State == DrawItemState.Focus)
e.DrawFocusRectangle();
var index = e.Index;
if(index < 0 || index >= Items.Count) return;
var item = Items[index];
string text = (item == null)?"(null)":item.ToString();
using(var brush = new SolidBrush(e.ForeColor))
{
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString(text, e.Font, brush, e.Bounds);
}
}
}