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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:38:22+00:00 2026-06-10T14:38:22+00:00

I have been learning about drawing to panels using bitmaps. I thought I would

  • 0

I have been learning about drawing to panels using bitmaps. I thought I would run a trial program to simply turn a white panel black. (May seem a complicated way of doing it but this is just to test the basics) My program is as follows:

public partial class Form1 : Form
{
    private Bitmap buffer = new Bitmap(100,100);

    public Form1()
    {
        InitializeComponent();
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {
       e.Graphics.DrawImageUnscaled(buffer, Point.Empty);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 100; i++)
        {
            for (int j = 0; j < 100; j++)
            {
                buffer.SetPixel(i, j, Color.Black);
            }
        }
    }
}

When I run it and press the button the panel does not seem to change. Any Idea where I am going wrong. Thank you in advance.

  • 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-10T14:38:24+00:00Added an answer on June 10, 2026 at 2:38 pm

    You have to invalidate the panel’s client area so that Windows will force a repaint. But there are some other issues:

    1. FillRectangle will do a much more efficient job than painting each pixel in a loop, as @Tony suggested.
    2. You might hit concurrency issues if the panel is invalidated before buffer is ready to be displayed. Be sure that the bitmap generation is isolated from its presentation.

    These suggestions are summarized (but not tested) as follows:

    private void button1_Click(object sender, EventArgs e)
    {
        Bitmap tempBuffer = new Bitmap(100, 100);
    
        using (Graphics g = Graphics.FromImage(tempBuffer))
        using (SolidBrush blackBrush = new SolidBrush(Color.Black))
        {
            g.FillRectangle(blackBrush, new Rectangle(0, 0, tempBuffer.Width-1, tempBuffer.Height-1);
        }
    
        buffer = tempBuffer;
        panel1.Invalidate();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning about TDD (using JUnit) and I have a doubt about
I have recently been learning more about design patterns and thought I'd take a
I have recently been learning about vertex coloring . The program worked fine when
I have been learning about Delegation and Data Sources for iOS programming and need
Recently I have been learning about WMI and WQL. I found out the list
I have been learning the Definitive Guide of JavaScript.i got a question about the
I am currently learning about basic networking in java. I have been playing around
I've been learning wpf for about a week now.. and i have a basic
I have been learning about various functional languages for some time now including Haskell,
I'm 14 and have been learning java for about 4/5 months. I'm coding 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.