Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add padding between items in a listbox?

I'm wondering if there's a way to add padding between my line items. It's a form intended to be used on a tablet, and space between each one would make it easier to select different items.

Anyone know how I can do this?

like image 697
Claire Avatar asked Mar 08 '13 16:03

Claire


1 Answers

There is an ItemHeight property.

You have to change DrawMode property to OwnerDrawFixed to use custom ItemHeight.

When you use DrawMode.OwnerDrawFixed you have to paint/draw items "manually".

Here is an example: Combobox appearance

Code from link above (written/provided by 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);
        }
    }
}
like image 110
Kamil Avatar answered Sep 27 '22 23:09

Kamil