- - PR -
CustomComboBoxについて
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2008-06-08 15:44
お世話になっております。BBQと申します。
環境は、.NET Framework 2.0です。 ComboBoxを継承してComboBoxRendererで外観を描画したのですが、DropDownStyleをDropDownにすると ComboBoxクラスがTextBoxを前面表示するため?、幅を広げたDropDownButtonの上にTextBoxが描画されてしまいます。 また、ItemHeightプロパティの値を変更するとTextBoxの下部に黒い太線が描画されます。 (たぶんTextBoxが描画されていない部分) これを回避する方法ってないでしょうか? 宜しくご教示ください。 [C#] public class CustomComboBox : ComboBox { private const int COMBO_BOX_WIDTH = 200; private const int COMBO_BOX_HEIGHT = 30; private const int COMBO_BTN_WIDTH = 30; private const int COMBO_BTN_HEIGHT = 30; private Rectangle txtRect = new Rectangle(0, 0, COMBO_BOX_WIDTH, COMBO_BOX_HEIGHT); private Rectangle rect = new Rectangle(COMBO_BOX_WIDTH - COMBO_BTN_WIDTH - 1, 1, COMBO_BTN_WIDTH, COMBO_BTN_HEIGHT - 2); private ComboBoxState cb_State = ComboBoxState.Normal; public CustomComboBox() { this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.DropDownStyle = ComboBoxStyle.DropDown; this.FlatStyle = FlatStyle.Flat; this.DrawMode = System.Windows.Forms.DrawMode.Normal; this.ItemHeight = 24; this.Width = COMBO_BOX_WIDTH; this.Height = COMBO_BOX_HEIGHT; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); ComboBoxRenderer.DrawTextBox(e.Graphics, txtRect, cb_State); ComboBoxRenderer.DrawDropDownButton(e.Graphics, rect, cb_State); } } |
1