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

  • SEARCH
  • Home
  • 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 8468585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:58:35+00:00 2026-06-10T15:58:35+00:00

In a custom control, deriving from Button, the ButtonRenderer.DrawButton() draws a button, in various

  • 0

In a custom control, deriving from Button, the ButtonRenderer.DrawButton() draws a button, in various states.

All is fine when the display settings in Windows are set to a color-depth of 32-bits, but once, it is set to 16-bits, the color does not match one of a regular WinForms button and it stands out in my UI, which I do not really want.

I’ve replicated this using a minimal example code like this.

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        Rectangle rect = new Rectangle(10, 10, 250, 120);
        ButtonRenderer.DrawButton(e.Graphics, rect, PushButtonState.Normal);

        rect = new Rectangle(300, 300, 250, 120);
        ControlPaint.DrawButton(e.Graphics, rect, ButtonState.Normal);
    }

which gives this…

Rendered Buttons

I’m sure you will all notice that the two “buttons” drawn by the DrawButton methods have a slightly lighter color than the standard button, and Form background (which I didn’t change and left as the default which is “Control”)…
If you zoom enough, you can see that it is alternating pixels of the correct background color and another brighter color…

I spotted this issue because our users are using Remote Desktop (RDP) to connect to our applications. Forcing the remote desktop settings to 32-bits resolves the problem but I think it has a performance impact, and some of our users are working overseas over relatively slow broadband links… so enforcing 32-bits is an option I would prefer to avoid.
It also happens in front of a PC, by setting the display settings to 16-bits colors.

Do you please have any ideas? Is it some kind of bug with ButtonRenderer and ControlPaint classes, or is there a way around this? (I’m using .Net 4.0).

  • 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-06-10T15:58:36+00:00Added an answer on June 10, 2026 at 3:58 pm

    ControlPaint.DrawButton is a wrapper around Win32’s DrawFrameControl.

    It renders to a bitmap, then draws the bitmap to your Graphics display context. The color dithering/approximation is happening at that bitmap layer. I ran out of time to experiment further but…

    If you merely call DrawFrameControl yourself, all works:

    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern bool DrawFrameControl(IntPtr hDC, ref RECT rect, int type, int state);
    
    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    
        public RECT(Rectangle r)
        {
            this.left = r.Left;
            this.top = r.Top;
            this.right = r.Right;
            this.bottom = r.Bottom;
        }
    }
    
    protected override void OnPaint(PaintEventArgs e)
    {
        if (Application.RenderWithVisualStyles)
             ButtonRenderer.DrawButton(.....)
        else
        {
             var rect = new RECT(new Rectangle(10, 110, 100, 100));
             DrawFrameControl(e.Graphics.GetHdc(), ref rect, 4, 0x10 | (int)ButtonState.Normal);
        }
    
        base.OnPaint(e);
    }
    

    EDIT: Added optional call to themes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom control by deriving from a ZedGraphControl I need
I am deriving a custom control from StackPanel (or just using the usual UserControl
Having a custom control deriving from ScrollableControl and using AutoScrollMinSize to set the inner
I'm trying to create a custom control (deriving from Control ) with its own
I'm having a class where I'm deriving from System.Windows.Forms.Control [Serializable] public class CommonControl :
I am deriving a custom control from TVirtualDrawTree and I am overriding the DoPaintBackground
I am writing a custom control deriving from UserControl . In it are some
I'm building a custom control in Silverlight by deriving from ContentControl and doing some
I have a custom container control (deriving from FlowLayoutPanel ) which contains zero or
I am creating a custom control(deriving from Control ) and want to define a

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.