Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ComboBox Custom OnPaint

ComboBox Custom OnPaint

Scheduled Pinned Locked Moved C#
graphicshelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ian
    wrote on last edited by
    #1

    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;

    L 1 Reply Last reply
    0
    • I 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;

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      --Ian wrote:

      base.OnPaint(e);

      I think you dont need to call that :)**

      xacc.ide-0.2.0 preview - Now in 100% C# goodness

      **

      I 1 Reply Last reply
      0
      • L leppie

        --Ian wrote:

        base.OnPaint(e);

        I think you dont need to call that :)**

        xacc.ide-0.2.0 preview - Now in 100% C# goodness

        **

        I Offline
        I Offline
        Ian
        wrote on last edited by
        #3

        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;

        I 1 Reply Last reply
        0
        • I Ian

          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;

          I Offline
          I Offline
          Ian
          wrote on last edited by
          #4

          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;

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups