ComboBox Custom OnPaint
-
I have a control that is derived from the standard ComboBox. I have an override for the OnPaint method that paints a border, drop down arrow button, background, and foreground. The only problem is that something (some other event/subcontrol) is drawing a black text box with a large font over top of the text box region of the combo box control. I am drawing a background in my OnPaint event, and it is being draw on top of. I can see that the background is drawn because there is a border around the text box region. My code looks like the following: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); DrawBorder(); DrawBackground(); DrawArrowButton(); DrawForegroundText(); } What am I missing here??? By the way, this control works just fine if the DropDownStyle is set to DropDownList, however I'm need it to work as a DropDown (being able to edit the text box). --Ian;
-
I have a control that is derived from the standard ComboBox. I have an override for the OnPaint method that paints a border, drop down arrow button, background, and foreground. The only problem is that something (some other event/subcontrol) is drawing a black text box with a large font over top of the text box region of the combo box control. I am drawing a background in my OnPaint event, and it is being draw on top of. I can see that the background is drawn because there is a border around the text box region. My code looks like the following: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); DrawBorder(); DrawBackground(); DrawArrowButton(); DrawForegroundText(); } What am I missing here??? By the way, this control works just fine if the DropDownStyle is set to DropDownList, however I'm need it to work as a DropDown (being able to edit the text box). --Ian;
--Ian wrote:
base.OnPaint(e);
I think you dont need to call that :)**
xacc.ide-0.2.0 preview - Now in 100% C# goodness
**
-
--Ian wrote:
base.OnPaint(e);
I think you dont need to call that :)**
xacc.ide-0.2.0 preview - Now in 100% C# goodness
**
-
Actually it doesn't matter if I call base.OnPaint(e), because I'm doing my custom paint stuff after the call. Either way, if you remove the call, the text box is still drawn by something else. --Ian;
The sample class below does not contain all the code, however it will give you an idea of the problem. Just drop this class into your a project, compile, and drop it the ComboDraw control onto a form.
using System; using System.Collections.Generic; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ComboTest { class ComboDraw : ComboBox { public ComboDraw() { DrawMode = DrawMode.OwnerDrawFixed; DropDownStyle = ComboBoxStyle.DropDown; FlatStyle = FlatStyle.Flat; SetStyle(ControlStyles.UserPaint, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.FillRectangle(new SolidBrush(Color.Green), ClientRectangle); } } }
--Ian;