Overriding OnPaint on ComboBox

Hello,

I'm newbie in C# and .NET and I need to use user control inherited from combobox.

So, in constructor I set:


SetStyle(ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);

Now I can free paint over my combobox, but over everything I painted is uggly black box, which represents the place where the new typed text is placed. This text is draw by standard system font Black on White, and ignores font settings in control params.

Can anyone say me, why the control behaves like this

Thanx



Answer this question

Overriding OnPaint on ComboBox

  • CheeseBob

    The bad news is that the ComboBox uses the painting methods of the OS, so overriden the OnPaint(..) really isn't good enough.

    The good news is that if you want to paint the items appearance (including the one that is selected on shown when not in drop down mode, you can do this:

    lst.DrawMode = DrawMode.OwnerDrawFixed;

    And than override the OnDrawItem, to draw each item your own.



  • Rob MacFadyen

    I tried this, but it works only for listed items in dropdown. How can I draw item which is just written. This item is probably not member of Items collection.

  • JR-MDX

    From the MSDN:

    ComboBox.Paint Event

    This event supports the .NET Framework infrastructure and is not intended to be used directly from your code.

    Remarks

    This event is not relevant for this class.

    But maybe you should check this linkes:

    http://www.codeproject.com/cs/miscctrl/ReadOnlyComboBox.asp

    http://www.codeproject.com/cs/miscctrl/CGFontCombo.asp

    Both articales took the combobox and gave it more, so maybe you can find something there.



  • Overriding OnPaint on ComboBox