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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:09:50+00:00 2026-05-22T15:09:50+00:00

I am working on a simple windows forms paint application. I am having problem

  • 0

I am working on a simple windows forms paint application. I am having problem in clearing the panel. The code i am using to draw is

private void panel1_Paint(object sender, PaintEventArgs e)
{
    Graphics g = Graphics.FromImage(tempDraw);
    Pen myPen = new Pen(foreColor, lineWidth);
    g.DrawLine(myPen, x1, y1, x2, y2);
    myPen.Width = 100;
    myPen.Dispose();
    e.Graphics.DrawImageUnscaled(tempDraw, 0, 0);
    g.Dispose();
 }

How to clear the panel?

  • 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-22T15:09:51+00:00Added an answer on May 22, 2026 at 3:09 pm

    Are drawing in the paint handler of the Panel instance? If not then calling Invalidate on the panel would do.

    But you will probably be persisting the drawing items and so to clear them you would need to delete what has been drawn and then call Invalidate. You could also fill the Panel with a particular color using FillRect but that would be a dirty workaround and not fit your final design.

    You should also check out CodeProject.com for examples like this one to give you an idea on what needs to be handled when creating a drawing app like this.

    EDIT:

    Per the edited answer, you cannot clear the panel with the existing logic. You are painting inside Paint handler of the form which will happen any time it needs to be redrawn. This means that you should change your approach. You need some sort of condition inside the Paint handler which decides whether or not it will paint anything at all. This is where the persistence of drawing objects comes in. If you want to create a drawing program then you will have to handle the mouse Down, Up and Move events over the panel objects and store the data in a points array. (As an example of one type of drawing.) Then in your Paint handler if the Points[] is not empty you draw the points. Otherwise you draw nothing… which ends up in an empty container. Then if you need to clear the drawing you delete the contents of the Points array and call Invalidate on the Panel. That will clear the persisted data and repaint to nothing.

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

Sidebar

Related Questions

I am working on a simple chat application using a System.Windows.Forms.WebBrowser Control to display
I have a Windows Forms application that I'm working on, but I'm having trouble
I'm developing a windows forms application using VB.NET. I'm currently working on DataReport (by
I'm working on a windows forms application (C#) where a user is entering data
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
I'm working on a simple 2D game engine in Java, and having no trouble
I'm working on a simple application to start learning my way around WPF. I
I am working on an application which draws a simple dot grid. I would
I'm writing a simple Windows Forms utility to screenshot either the entire screen or
I'm currently working on the user interface of a win forms application. The primary

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.