Cla*_*ire 4 c# listbox padding winforms visual-studio-2012
我想知道是否有办法在我的订单项之间添加填充.这是一个用于平板电脑的表格,每个表格之间的空间可以更容易地选择不同的项目.
谁知道我怎么做到这一点?
有一个ItemHeight属性.
您必须将DrawMode属性更改OwnerDrawFixed为使用自定义ItemHeight.
使用时DrawMode.OwnerDrawFixed,必须"手动"绘制/绘制项目.
这是一个例子:Combobox外观
上面链接的代码(由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);
}
}
}
Run Code Online (Sandbox Code Playgroud)