How to change the value of a CheckedListBox object

I need to change the vertical space for CheckedListBox elements CheckedListBox that they match the text fields on the other side:

CheckedListBox and "TextBox" s side to side How to do it?

After doing some research, I found that the CheckedListBox inherits from the ListBox , so it should have its own public ItemHeight , but for some reason it doesn't

I tried this:

 ListBox l = CheckedList as ListBox; l.ItemHeight = 30; 

but it did not work

+6
source share
2 answers

By default, the ItemHeight property of a CheckedListBox is

 public override int ItemHeight { get { // this should take FontHeight + buffer into Consideration. return Font.Height + 2; } set { } } 

you can purely override this property in a new class.

 public sealed class MyListBox:CheckedListBox { public MyListBox() { ItemHeight = 30; } public override int ItemHeight { get; set; } } 

this should allow you to set your own ItemHeight.

enter image description here

+17
source

This works in VS2013 net FrameWork4.5 VB code

Place the declaration and constant at the top of the class

Usage places the rest of the code in Form_Load, as in the code example.

 Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As IntPtr, ByVal wMsg As UInt32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr Private Const lB_SETITEMHEIGHT As Integer = &H1A0 Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ItemHeight As Integer = Me.Font.Height + 4 SendMessageByNum(CheckedListBoxControl.Handle, lB_SETITEMHEIGHT, CType(0, IntPtr), CType(ItemHeight, IntPtr)) End Sub 
+1
source

Source: https://habr.com/ru/post/1392285/


All Articles