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 7942905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:06:57+00:00 2026-06-04T00:06:57+00:00

I have two problems with an own user control which uses bitmaps: It flickers

  • 0

I have two problems with an own user control which uses bitmaps:

  1. It flickers if it’s redrawn via .NET’s ‘Refresh’ method.
  2. It has a bad performance.

The control consists of three bitmaps:

  • A static background image.
  • A rotating rotor.
  • Another image depending on rotor angle.

All used bitmaps have a resolution of 500×500 pixels. The control works like this:
https://www.dropbox.com/s/t92gucestwdkx8z/StatorAndRotor.gif (it’s a gif animation)

The user control should draw itself everytime it gets a new rotor angle. Therefore, it has a public property ‘RotorAngle’ which looks like this:

public double RotorAngle
{
    get { return mRotorAngle; }
    set
    {
        mRotorAngle = value;
        Refresh();
    }
}

Refresh raises the Paint event. The OnPaint event handler looks like this:

private void StatorAndRotor2_Paint(object sender, PaintEventArgs e)
{
    // Draw the three bitmaps using a rotation matrix to rotate the rotor bitmap.
    Draw((float)mRotorAngle);
}

But when I use this code – which works well in other own user controls – the user control is not drawn at all if control is double buffered via SetStyle(ControlStyles.OptimizedDoubleBuffer, true). If I don’t set this flag to true, the control flickers when being redrawn.

In control constructor I set:

SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ContainerControl, false);
// User control is not drawn if "OptimizedDoubleBuffer" is true.
// SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);

First, I thought it flickers because the background is cleared everytime the control is drawn. Therefore, I set SetStyle(ControlStyles.AllPaintingInWmPaint, true). But it didn’t help.

So, why does it flicker? Other controls work very well with this setup. And why is the controly not drawn if SetStyle(ControlStyles.OptimizedDoubleBuffer, true).

I found out that the control does not flicker if I invoke my Draw method directly after changing the property RotorAngle:

public float RotorAngle
{
    get { return mRotorAngle; }
    set
    {
        mRotorAngle = value;
        Draw(mRotorAngle);
    }
}

But this results in a very bad performance, especially in full screen mode. It’s not possible to update the control every 20 milliseconds. You can try it yourself. I will attach the complete Visual Studio 2008 solution below.

So, why it is such a bad performance? It’s no problem to update other (own) controls every 20 milliseconds. Is it really just due to the bitmaps?

I created a simple visual Visual Studio 2008 solution to demonstrate the two problems:
https://www.dropbox.com/s/mckmgysjxm0o9e0/WinFormsControlsTest.zip (289,3 KB)

There is an executable in directory bin\Debug.

Thanks for your help.

  • 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-04T00:06:59+00:00Added an answer on June 4, 2026 at 12:06 am

    First, per LarsTech’s answer, you should use the Graphics context provided in the PaintEventArgs. By calling CreateGraphics() inside the Paint handler, you prevent OptimizedDoubleBuffer from working correctly.

    Second, in your SetStyle block, add:

    SetStyle( ControlStyles.Opaque, true );
    

    … to prevent the base class Control from filling in the background color before calling your Paint handler.

    I tested this in your example project, it seemed to eliminate the flickering.

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

Sidebar

Related Questions

I have my program that can draw rectangles. I have two problems I can't
I have two cmake-related problems: first, I can't make it to find the includes
I have some localization problems in my webpage. There are basically two problems (that
We are having some problems deploying our WCF services into IIS7. We have two
I'm having some problems trying to perform a query. I have two tables, one
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User
This is better explained in: http://jsfiddle.net/tRBaV/1/ I have two kinds of entities: containers and
So I have two filtering objects. One is a drop down list, which chooses
I have two websites, let's say they're example.com and anotherexample.net . On anotherexample.net/page.html ,
I'm having a problems with the Graphics.DrawString() method. My UserControl uses a monospaced font

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.