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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:25:24+00:00 2026-05-14T08:25:24+00:00

Hey, I need to do my drawing over a panel in C# but without

  • 0

Hey, I need to do my drawing over a panel in C# but without placing my drawing code inside “panel1_Paint”, how can I do that ??
BTW, I’m using WinForms.

Update : I forgot to make something clear, I need not to place my drawing code inside paint handler, because I need to start drawing depending on buttons’ events.

  • 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-14T08:25:24+00:00Added an answer on May 14, 2026 at 8:25 am

    Usually you do all your drawings in the paint event handler. If you want to do any update (if a user clicks on the panel for example) you have to defer that action: you store the required data (coordinates where the user clicked) and force a redraw of the control. This causes the paint event to be fired, where you can then draw things you stored before.

    Another way would be (if you really want to draw outside of the ‘panel1_Paint’ event handler) to draw inside a buffer image, and copy the image to the controls graphics object in the paint event handler.

    Update:

    An example:

    public class Form1 : Form
    {
        private Bitmap buffer;
    
        public Form1()
        {
            InitializeComponent();
    
            // Initialize buffer
            panel1_Resize(this, null);
        }
    
        private void panel1_Resize(object sender, EventArgs e)
        {
            // Resize the buffer, if it is growing
            if (buffer == null || 
                buffer.Width < panel1.Width || 
                buffer.Height < panel1.Height)
            {
                Bitmap newBuffer = new Bitmap(panel1.Width, panel1.Height);
                if (buffer != null)
                    using (Graphics bufferGrph = Graphics.FromImage(newBuffer))
                        bufferGrph.DrawImageUnscaled(buffer, Point.Empty);
                buffer = newBuffer;
            }
        }
    
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            // Draw the buffer into the panel
            e.Graphics.DrawImageUnscaled(buffer, Point.Empty);
        }
    
    
    
        private void button1_Click(object sender, EventArgs e)
        {
            // Draw into the buffer when button is clicked
            PaintBlueRectangle();
        }
    
        private void PaintBlueRectangle()
        {
            // Draw blue rectangle into the buffer
            using (Graphics bufferGrph = Graphics.FromImage(buffer))
            {
                bufferGrph.DrawRectangle(new Pen(Color.Blue, 1), 1, 1, 100, 100);
            }
    
            // Invalidate the panel. This will lead to a call of 'panel1_Paint'
            panel1.Invalidate();
        }
    }
    

    Now the drawn images wont be lost, even after a redraw of the control, because it only draws out the buffer (the image, saved in the memory). Additionally you can draw things anytime a event occurs, by simply drawing into the buffer.

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

Sidebar

Related Questions

Hey, I'm using php 5 and need to communicate with another server that runs
Hey can any one tell me should i need open a port for outgoing
Hey, I need to delete all images from a string and I just can't
Hey I am using c++ to write a program which has a drawing area.
Hey, I need to write a program for OSX that will cause my macbook
Hey guys I need to print a project that I wrote in C to
Hey everyone, I have a database result that returns from a method. I need
Hey all, I need to compare a double inside an if statement. If the
Hey guys, I need to make a list of some functions that are listed
Hey all i have 2 dates that i need to see the days that

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.