The owner of the variable size draws a ComboBox; the list is not correct

I deduced the class from ComboBox, made it a processed owner list (DrawMode.OwnerDrawVariable style), and redefined OnMeasureItem and OnDrawItem. I am adding special elements to the drop-down list (e.g. delimiters) that are smaller / larger than regular elements that reside in the control.

Now the problem that I have encountered and cannot effectively fix is ​​the size of the drop-down list: an ugly empty space appears at the end of the list when it crashes. I thought I solved this by setting the DropDownHeight ComboBox property to the sum of all the element heights, but this does not seem to work all the time. Sometimes, with a random number of elements, an empty empty space is returned. This is an unusual problem, but hopefully a common and easily fixed one.

How can I get a combo box dropdown exactly for the size occupied by the elements inside?

+5
source share
3 answers

ComboBox.UpdateDropDownHeight(). DropDownHeight , , . , DrawMode, .

:

  int height = ...; // Your code here
  if (height == 106) ++height;
  comboBox1.DropDownHeight = height;

, OnDrawItem().

+4

.

, DropDownHeight . , , Windows.

, . ( ) , , .

+2

I assume the problem is how you calculate the height of the dropdown list, I think it is smth like this:

comboBox.DropDownHeight = N_of_items * item_height;

the overall height of the dropdown should also include the upper and lower border of the border, so if you would do something like this:

comboBox.DropDownHeight = N_of_items * item_height + SystemInformation.BorderSize.Height*2;

he should do the trick and show a dropdown without white areas

hope this helps, believes

+1
source

All Articles