Open In App

How to set the Height of the Elements present in the ListBox in C#?

In Windows Forms, ListBox control is used to show multiple elements in a list, from which a user can select one or more elements and the elements are generally displayed in multiple columns. In ListBox, you can set the height of the elements present in the ListBox using the ItemHeight Property of the ListBox. The maximum height of the ListBox item is 255 pixels. You can set this property in two different ways:

1. Design-Time: It is the easiest way to set the height of the elements present in the ListBox as shown in the following steps:



2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the height of the elements present in the ListBox control programmatically with the help of given syntax:



public virtual int ItemHeight { get; set; }

Here, the value of this property is of System.Int32 type. The height of the element is always considered in pixels. It will throw an ArgumentOutOfRangeException if the value of this property was set to less than 0 or more than 255 pixels. The following steps show how to set the height of the elements present in the ListBox dynamically:


Article Tags :
C#