実行時ComboBoxに(Windowsフォームコントロールから)の高さをX に設定したい。
私は持っています
DrawModeプロパティをに設定してOwnerDrawVariable、アイテムを手動で描画することを指定します。IntegralHeightプロパティがfalseに設定され、が自動的にサイズ変更されないようにしControlます。- の
ItemHeightプロパティもXComboBoxに設定されます。
DrawItemまた、comboBoxのアイテムのイベントとイベントをオーバーライドしましたMeasureItem(以下のコードを参照)
ただし、実行時にComboBoxのを設定すると、がに設定されている場合にのみ機能します。HeightDropDownStyleSimple
これは、プログラムで(ComboBox'sHeightまたはSize)プロパティを変更する方法とPropertyGrid、アプリにあるコントロールを使用する方法の両方で行います。
aDropDownまたはの高さを設定するDropDownList ComboBoxと、Windowsが自動的に高さを別の値Yに変更することに気付きました(デバッグ後、何らかの理由でX + 6であることに気付きました)。
私は何が欠けていますか?なぜこれが起こるのですか?
ハンドラーからのコードは次のとおりです。
private void DrawItemHandler(object sender, DrawItemEventArgs e)
{
//Create a new font to write the item
Font ComboItemFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular);
e.DrawBackground();
e.DrawFocusRectangle();
//Write the item's value
e.Graphics.DrawString(((ComboBox) sender).Items[e.Index].ToString(),
ComboItemFont,
new SolidBrush(Color.Black),
e.Bounds);
//Update the source's font to match the current font
((Control) sender).Font = ComboItemFont;
}
private void MeasureItemHandler(object sender, MeasureItemEventArgs e)
{
//Do nothing
}