Controlling height of dropdown listbox in OwnerDrawn combobox

  • Thread starter Thread starter Aravind Thoram
  • Start date Start date
A

Aravind Thoram

Hi,
I am trying to create an owner drawn combo box wherein
the various items have different heights. So I am overriding
the OnMeasureItem method to set the ItemHeight. I am
drawing the ComboBox items in the OnDrawItem method.
When the number of items in the ComboBox is equal to 1
somehow the size of the drop down list box displayed is smaller than
the item height set by me. Even when the number of items
are greater than 1, I am not able to control the size of the drop down
list box that is displayed. I would be very much thankful if someone
could point out how I can control the size of the listbox that is
displayed.

Thanks again in advance.
rgds
-aravind.

public Form1() {
InitializeComponent();
this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
this.comboBox1.IntegralHeight = false;
this.comboBox1.DrawItem +=new DrawItemEventHandler(ComboboxDrawItem);
this.comboBox1.MeasureItem += new
System.Windows.Forms.MeasureItemEventHandler(this.MyOnMeasureItem);
}

private void Form1_Load(object sender, System.EventArgs e) {
this.comboBox1.Items.Add("One");
}



private void ComboboxDrawItem(object sender, DrawItemEventArgs e) {
if (-1 < e.Index) {
e.Graphics.FillRectangle(new SolidBrush(Color.Pink), e.Bounds.X,
e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawRectangle(new Pen(Color.Black), e.Bounds.X, e.Bounds.Y,
e.Bounds.Width-1, e.Bounds.Height-1);
e.Graphics.DrawString(this.comboBox1.Items[e.Index].ToString(),
SystemInformation.MenuFont, new SolidBrush(Color.Blue), e.Bounds);

}
}


private void MyOnMeasureItem(object sender,
System.Windows.Forms.MeasureItemEventArgs e) {
if (-1 < e.Index) {
e.ItemHeight = 35;
}
}
 
Back
Top