我想知道是否有办法在我的订单项之间添加填充。这是一种旨在在平板电脑上使用的表格,每个表格之间的空间可以更轻松地选择不同的项目。
有人知道我该怎么做吗?
最佳答案
有一个 ItemHeight
属性。
您必须将 DrawMode
属性更改为 OwnerDrawFixed
才能使用自定义 ItemHeight
。
当您使用 DrawMode.OwnerDrawFixed
时,您必须“手动”绘制/绘制项目。
这是一个例子:Combobox appearance
来自上面链接的代码(由 max 编写/提供):
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);
}
}
}
关于c# - 如何在列表框中的项目之间添加填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15298701/