如何在列表框中的项目之间添加填充? [英] How to add padding between items in a listbox?

查看:76
本文介绍了如何在列表框中的项目之间添加填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在订单项之间添加填充.这是一种打算在平板电脑上使用的表格,并且每个表格之间的空间将使选择不同的项目变得更加容易.

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?

推荐答案

有一个ItemHeight属性.

您必须将DrawMode属性更改为OwnerDrawFixed才能使用自定义ItemHeight.

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

使用DrawMode.OwnerDrawFixed时,您必须手动"绘制/绘制项目.

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

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

上面链接中的代码(由 max 编写/提供):

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);
        }
    }
}

这篇关于如何在列表框中的项目之间添加填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆