如何更改CheckedListBox项目的垂直空间

Sta*_*tar 6 c# checkedlistbox winforms

我需要更改CheckedListBox项目的垂直空间,以便它们适合另一侧的文本框:

CheckedListBox与"TextBox"并排http://i40.tinypic.com/358vt52.png 如何做到这一点?

在做了一些研究后,我发现CheckedListBox继承ListBox,所以它必须有它的公共财产ItemHeight,但由于某种原因它没有

我试过这个:

ListBox l = CheckedList as ListBox;
        l.ItemHeight = 30;
Run Code Online (Sandbox Code Playgroud)

但它不起作用

cry*_*ted 17

CheckedListBox的ItemHeight属性的默认实现是,

public override int ItemHeight { 
        get {
            // this should take FontHeight + buffer into Consideration.
            return Font.Height + 2;
        } 
        set {
        } 
    } 
Run Code Online (Sandbox Code Playgroud)

您可以在新类中干净地覆盖此属性.

public sealed class  MyListBox:CheckedListBox
    {
        public MyListBox()
        {
            ItemHeight = 30;
        }
        public override int ItemHeight { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

这应该允许您设置自己的ItemHeight.

在此输入图像描述