checkedlistbox item height [modified]
-
Hallo Does anybody know how to change the height of an item in a checkedlistbox control. I have tried setting the drawmode to OwnerDrawVariable and drawing each item myself but with no success. Any clues would be greatly appreciated. Thanks -- modified at 1:47 Tuesday 15th May, 2007
There are 10 types of people in the world, those who understand binary and those who dont.
-
Hallo Does anybody know how to change the height of an item in a checkedlistbox control. I have tried setting the drawmode to OwnerDrawVariable and drawing each item myself but with no success. Any clues would be greatly appreciated. Thanks -- modified at 1:47 Tuesday 15th May, 2007
There are 10 types of people in the world, those who understand binary and those who dont.
When the DrawMode property is set to DrawMode.OwnerDrawFixed, all items have the same height. When the DrawMode property is set to DrawMode.OwnerDrawVariable, the ItemHeight property specifies the height of each item added to the ListBox. Because each item in an owner-drawn list can have a different height, you can use the GetItemHeight method to get the height of a specific item in the ListBox. If you use the ItemHeight property on a ListBox with items of variable height, this property returns the height of the first item in the control.
-
When the DrawMode property is set to DrawMode.OwnerDrawFixed, all items have the same height. When the DrawMode property is set to DrawMode.OwnerDrawVariable, the ItemHeight property specifies the height of each item added to the ListBox. Because each item in an owner-drawn list can have a different height, you can use the GetItemHeight method to get the height of a specific item in the ListBox. If you use the ItemHeight property on a ListBox with items of variable height, this property returns the height of the first item in the control.
That only works for a listbox though. If you try that on a checkedlistbox it wont work. The checkedlistbox is inherited from the listbox and hardcodes the height to its fontsize + 2. The only way to change the height is to change the font size or alternatively draw the checkboxes to an ordinary listbox that is set to OwnerDrawVariable. Thanks though, you wouldn't believe how long I was stuck on this :doh:
There are 10 types of people in the world, those who understand binary and those who dont.
-
Hallo Does anybody know how to change the height of an item in a checkedlistbox control. I have tried setting the drawmode to OwnerDrawVariable and drawing each item myself but with no success. Any clues would be greatly appreciated. Thanks -- modified at 1:47 Tuesday 15th May, 2007
There are 10 types of people in the world, those who understand binary and those who dont.
This works in VS2013 net FrameWork4.5 Put declare and constant at top of class Usage put rest of code in Form_Load as in example code.
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 IntPtrPrivate 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
Douglas Peterson Senior Application Developer / Chief Technical Officer The Professional PC / ERIC Systems
-
This works in VS2013 net FrameWork4.5 Put declare and constant at top of class Usage put rest of code in Form_Load as in example code.
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 IntPtrPrivate 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
Douglas Peterson Senior Application Developer / Chief Technical Officer The Professional PC / ERIC Systems