c# - 如何在列表框中的项目之间添加填充?

标签 c# winforms visual-studio-2012 listbox padding

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

有人知道我该怎么做吗?

最佳答案

有一个 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/

相关文章:

C# 将数据从datagridview导出到excel

javascript - 我的 div 在第一次执行后消失

c# - ChildWindow (Silverlight) 设计问题标题上的按钮

c# - 替换多个文件中的文本但保留原始文本

c# - 用于 DataGridView (Windows.Forms) 和过滤的数组、列表或数据表

C# 如何缩短这个超长的重载 do while 语句

c# - 如何将变量数据传递到 .NET MAUI GraphicsView Canvas 中

c# - SharpDX vs SlimDX 用于游戏开发?

c# - ASP.NET 4.5 MVC4 模型绑定(bind)问题 - 无法定义任何模型

c++ - 整数压缩库