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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:46:51+00:00 2026-06-07T17:46:51+00:00

Today I am trying to solve problem with a blinking panel, when I draw

  • 0

Today I am trying to solve problem with a blinking panel, when I draw onto it.

Lots of threads I read, like these:

  • how to stop flickering C# winforms,
  • Double buffering with Panel,
  • How can I draw on Panel so it does not blink?

So I tried to draw onto PictureBox, MyPanel with doubleBuffered, but the best solution I found, when I read, that I can’t use g.Clear() every time, after that, even on non-doubleBuffered panel, blinking disappeared.

I even read, that I should free Graphics after draw is done. So I use everywhere using(Graphics g = panel.CreateGraphics()).

So my question, is it a great idea to create graphics for bitmap only when I draw something to it? Because before I created Bitmap, and Graphics (only for this bitmap, not for all components), so I had Graphics available for this bitmap every time

Here is my code:

public void newSizeDrawing()
    {
        Size size = collector.getLetterSize(selectedName);
        Size drawingSize = new Size(size.Width * (pixelSizeArray[pixelSize] + 1),size.Height * (pixelSizeArray[pixelSize] + 1));
        bitmapDraw = new Bitmap(drawingSize.Width, drawingSize.Height);
        int width = (this.MinimumSize.Width - panelDraw.MinimumSize.Width) + drawingSize.Width + 10;
        int height = (this.MinimumSize.Height - panelDraw.MinimumSize.Height) + drawingSize.Height + 10;
        this.Size = new Size(
            (width > this.MinimumSize.Width) ? width : this.MinimumSize.Width,
            (height > this.MinimumSize.Height) ? height : this.MinimumSize.Height);
        zeroDrawPosition = new Point((panelDraw.Size.Width - bitmapDraw.Width) / 2 - 1, (panelDraw.Size.Height - bitmapDraw.Height) / 2 - 1);
        using (Graphics g = panelDraw.CreateGraphics())
        {
            g.Clear(panelDraw.BackColor);
        }
        redrawDrawingLetter();
    }
public void redrawDrawingLetter()
    {
        bool[][] grid = collector.getArray(selectedName);
        using (Graphics graphicDraw = Graphics.FromImage(bitmapDraw))
        {
            graphicDraw.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
            graphicDraw.Clear(panelDraw.BackColor);
            int pxSize = pixelSizeArray[pixelSize];
            for (int y = 0; y < grid.Length; y++)
            {
                for (int x = 0; x < grid[y].Length; x++)
                {
                    graphicDraw.FillRectangle((grid[y][x] ? Brushes.Black : Brushes.White), x * (pxSize + 1), y * (pxSize + 1), pxSize, pxSize);
                }
            }
        }
        redrawDrawingPanel();
    }
private void redrawDrawingPanel()
    {
        using (Graphics g = panelDraw.CreateGraphics())
        {
            if (bitmapDraw != null)
                g.DrawImage(bitmapDraw, zeroDrawPosition);
        }
    }
private void panelDraw_Paint(object sender, PaintEventArgs e)
    {
        redrawDrawingPanel();
    }

Nobody can explain to me how to draw in C# the best way. So maybe my code isn’t good, but that is reason why I asking how to do it correctly.

newSizeDrawing is called by myself only, when user click on + or – button. I have bool double-dimension array if pixel is on or off. This is program for drawing letters for microchips and LED display (often 8px height of letter).

I wrote a method that checks if the mouse moved from one “pixel” to another, so I don’t redraw it after every call mouseMove event, because “pixel” can be from 10×10 px to 30×30 px.

  • 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-07T17:46:52+00:00Added an answer on June 7, 2026 at 5:46 pm
    private void panelDraw_Paint(object sender, PaintEventArgs e)
    {
        redrawDrawingPanel();
    }
    

    This is fundamentally wrong. The Paint event passes e.Graphics to let you draw whatever you want to paint. When you turn on double-buffering, e.Graphics refers to a bitmap, it is initialized with the BackColor. You then proceed to drawing using another Graphics object you got from CreateGraphics(). That one draws directly to the screen.

    The flicker effect you see if very pronounced. For a split second you see what the other Graphics context draws. Then your panelDraw_Paint() method returns and Winforms draws the double-buffered bitmap. There’s nothing on it so it immediately erases what you drew.

    Modify the redrawDrawingPanel() method and give it an argument of type Graphics. Pass e.Graphics in the call. And only use that Graphics object, remove all calls to CreateGraphics().

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

Sidebar

Related Questions

I noticed something when I was trying to solve a problem today. The scalar
I ran into a problem today trying to override an implementation of an interface
I ran into a problem today when trying to set a field using FieldInfo.SetValue()
I'm re-evaluating my model and way I am trying to solve a particular problem.
I was given good direction to solve a problem today from here but I
I am very interested in Haskell and currently trying to solve this problem. To
I was today trying to figure out on working with WebService and found many
I've search all over today trying to find how to do this, and not
I ran across the caret operator in python today and trying it out, I
I came across Side-by-side Assemblies for the first time today while trying to install

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.