CheckedListBox 的 ItemHeight 属性?
ItemHeight Property for CheckedListBox?
所以我是编码新手,只是在摆弄 Visual C#。我试图 space 取出 CheckedListBox 中的项目,我意识到没有 ItemHeight 属性 与 ListBox 不同。我进行了一些搜索并发现了一些类似的主题,包括在本网站和其他网站上展示的操作。然而,正如我所说,我是编程新手,不知道如何实现此 thread 建议的代码。
有人可以指导我如何 "override a class" 之类的吗?用更简单的话告诉我在哪里以及如何通过将内容间隔开来使 CheckedListBox 更漂亮?
这里有两个例子:
- 具有固定项目高度的一个
- 一个从外部获取项目高度的工具,非常有用,因此您可以反复使用相同的控件
代码:
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;
}
}
}
注:
首先重建您的项目,然后在工具箱中找到您新创建的自定义控件 window。
所以我是编码新手,只是在摆弄 Visual C#。我试图 space 取出 CheckedListBox 中的项目,我意识到没有 ItemHeight 属性 与 ListBox 不同。我进行了一些搜索并发现了一些类似的主题,包括在本网站和其他网站上展示的操作。然而,正如我所说,我是编程新手,不知道如何实现此 thread 建议的代码。
有人可以指导我如何 "override a class" 之类的吗?用更简单的话告诉我在哪里以及如何通过将内容间隔开来使 CheckedListBox 更漂亮?
这里有两个例子:
- 具有固定项目高度的一个
- 一个从外部获取项目高度的工具,非常有用,因此您可以反复使用相同的控件
代码:
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;
}
}
}
注:
首先重建您的项目,然后在工具箱中找到您新创建的自定义控件 window。