所以,我刚开始编写代码,只是在使用VisualC#。我试图在CheckedListBox中划分项目,我意识到没有ItemHeight属性与ListBox不同。我做了一些搜索,并遇到了一些类似的线程,无论是在这个网站上,还有一些展示了该做什么。但是,就像我说的,我对编程非常陌生,不知道如何实现这个thread建议的代码。
有人能指导我如何“重写一个类”或什么的吗?用简单的话来说,告诉我在哪里和如何通过间隔这些东西来使CheckedListBox更漂亮?
发布于 2018-03-07 18:07:33
这里有两个例子:
代码:
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;
}
}
}注:
首先重建项目,然后在“工具箱”窗口中找到新创建的自定义控件。

https://stackoverflow.com/questions/49157598
复制相似问题