【问题标题】:ItemHeight Property for CheckedListBox? [duplicate]CheckedListBox 的 ItemHeight 属性? [复制]
【发布时间】:2018-03-07 17:10:12
【问题描述】:

所以我是编码新手,只是在使用 Visual C#。我试图将 CheckedListBox 中的项目隔开,但我意识到没有与 ListBox 不同的 ItemHeight 属性。我已经进行了一些搜索,并在此站点和其他站点上发现了一些类似的线程,这些线程都显示了该怎么做。然而,就像我说的,我对编程非常陌生,不知道如何实现这个thread 建议的代码。

有人可以指导我如何“覆盖课程”或其他什么吗?用更简单的话说,告诉我在哪里以及如何通过将内容分开来使 CheckedListBox 更漂亮?

【问题讨论】:

  • 它并没有比链接的帖子更简单。首先创建类,重建,然后将控件放在表单上。

标签: c# properties checkedlistbox


【解决方案1】:

这里有两个例子:

  • 具有固定项目高度的一个
  • 一种从外部获取项目高度的方法,非常有用,因此您可以反复使用相同的控件

代码:

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public class Example1 : CheckedListBox
    {
        public override int ItemHeight
        {
            get { return 100; }
        }
    }

    public class Example2 : CheckedListBox
    {
        private readonly Func<int> _itemHeight;

        public Example2(Func<int> itemHeight)
        {
            _itemHeight = itemHeight;
        }

        public override int ItemHeight
        {
            get { return _itemHeight(); }
        }
    }

    public class Example2Test
    {
        public Example2Test()
        {
            var example2 = new Example2(GetItemHeight);
        }

        private int GetItemHeight()
        {
            return 100;
        }
    }
}

注意:

首先重建您的项目,然后在工具箱窗口中找到您新创建的自定义控件。

【讨论】:

  • Tysm...我想我现在有点明白了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
相关资源
最近更新 更多