Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3272000
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:46:57+00:00 2026-05-17T18:46:57+00:00

I have an odd problem with an enhanced WinForms ComboBox I wrote in C#.

  • 0

I have an odd problem with an enhanced WinForms ComboBox I wrote in C#. The box shows a list of colors with the color itself and the name of the color and is set to ComboBoxStyle.DropDownList, double buffering and DrawMode.OwnerDrawFixed. The items are drawn when the DrawItem-event is raised.

If I open the DropDown menu and scroll with the mouse wheel the behaviour and look and feel is alright.
If I use the scrollbar thumb with the left mouse button the text in the panel gets all smudgy. Only if I hover over the shown items again the items will be redrawn correctly.

https://i.stack.imgur.com/F99Zu.png

Help is much appreciated!

Michael

Edit: Code of the drawing method:

    private void OnDrawItem(object sender, DrawItemEventArgs e)
    {
        if (e.Index == -1)
        {
            return;
        }

        e.DrawBackground();

        Graphics grfx = e.Graphics;
        grfx.FillRectangle(mWhiteBrush, e.Bounds);

        ColorInfo colorInfo = (ColorInfo)Items[e.Index];
        Color brushColor = colorInfo.Color;

        using (SolidBrush brush = new SolidBrush(brushColor))
        {
            Rectangle rectangleColor = e.Bounds;
            Rectangle rectangleText = e.Bounds;

            rectangleColor.Width = rectangleColor.Height;
            rectangleText.X += rectangleColor.Width;
            rectangleText.Width -= rectangleColor.Width;

            grfx.FillRectangle(brush, rectangleColor);
            grfx.DrawString(colorInfo.Name, e.Font, mBlackBrush, rectangleText);
        }    
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:46:58+00:00Added an answer on May 17, 2026 at 6:46 pm

    Without seeing the code, from your description, it sounds like there is a bug in your drawing code. One thing that I’ve seen in the past is that DrawItemEventArgs.State property of the event args can casue issues. It requires careful checking since it is a flag enum where multiple states can be set simultaneously.

    Post the drawing / measuring code for more insight.

    Also I assume you’ve double buffered this control, right?

    For a quick fix try setting this:

    grfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

    While a more robust solution is to handle the double buffering yourself in code as follows:

        private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
        {    
            if (e.Index == -1)
            {
                return;
            }
    
            using (Bitmap drawbuffer = new Bitmap(e.Bounds.Width, e.Bounds.Height))
            {
                using (Graphics grfx = Graphics.FromImage(drawbuffer))
                {
                    grfx.FillRectangle(mWhiteBrush, 0, 0, e.Bounds.Width, e.Bounds.Height);
    
                    ColorInfo colorInfo = (ColorInfo)Items[e.Index];
                    Color brushColor = colorInfo.Color;
    
                    using (SolidBrush brush = new SolidBrush(brushColor))
                    {
                        Rectangle rectangleColor = new Rectangle();
                        Rectangle rectangleText = new Rectangle();
    
                        rectangleColor.Height = rectangleColor.Width = e.Bounds.Height;
                        rectangleText.X += rectangleColor.Width;
                        rectangleText.Width = e.Bounds.Width - e.Bounds.Height;
    
                        grfx.FillRectangle(brush, rectangleColor);
                        grfx.DrawString(colorInfo.Name, e.Font, mBlackBrush, rectangleText);
                    }
    
                    e.Graphics.DrawImageUnscaled(drawbuffer, e.Bounds);
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an odd problem with Django. I have a set of objects that
I have an odd problem...I'm using a documentation generator which generates a lot of
I have an odd problem in VS2008 running unit tests. When I run the
I have the odd problem that I am not able to open the properties
I recently encountered an odd problem with RSACryptoServiceProvider.VerifyHash . I have a web application
I am having a really odd problem with Flash CS4. I have a MovieClip
I have an odd problem. Our company collects data and we use a HORRIBLE
I have an odd problem. In Eclipse Ganymede, I used to be able to
I have this odd problem with a third party script. On our site a
I have an odd problem with UIImagePickerControllerSourceTypeCamera. My application gives the choice to select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.