5

我想知道是否有办法在我的订单项之间添加填充。这是一种用于平板电脑的表格,每个表格之间的空间可以更容易地选择不同的项目。

有谁知道我该怎么做?

4

1 回答 1

8

有一个ItemHeight属性。

您必须将DrawMode属性更改OwnerDrawFixed为使用 custom ItemHeight

当您使用时,DrawMode.OwnerDrawFixed您必须“手动”绘制/绘制项目。

这是一个示例:组合框外观

来自上面链接的代码(由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);
        }
    }
}
于 2013-03-08T16:38:22.333 回答