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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:15:07+00:00 2026-06-14T04:15:07+00:00

I want to draw a line on a panel and then move it as

  • 0

I want to draw a line on a panel and then move it as the mouse moves. To do so, I draw the line and when the mouse moves I redraw the line to the new location and remove the previous line by drawing a line with the background color on it. It works fine if I do not use the high quality smoothing mode. But if use high quality smoothing mode, it leave traces on the panel. Does anybody know how to fix this? Thank you.
Here is the code

        int x_previous = 0;
        int y_previous = 0;

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            Pen pen1 = new System.Drawing.Pen(Color.Black, 3);
            Pen pen2 = new System.Drawing.Pen(panel1.BackColor, 3);
            Graphics g = panel1.CreateGraphics();
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.DrawLine(pen2, new Point(0, 0), new Point(x_previous, y_previous));
            g.DrawLine(pen1, new Point(0, 0), new Point(e.Location.X, e.Location.Y));
            x_previous = e.Location.X;
            y_previous = e.Location.Y;
        }

Here is the snapshot with SmoothingMode

Snapshot of the results

Here is the snapshot without SmoothingMode

Snapshot of the results

  • 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-14T04:15:09+00:00Added an answer on June 14, 2026 at 4:15 am

    Instead of drawing a line over a line, the safest option would be to clear the graphics using g.Clear(panel1.BackColor). This will wipe everything off that has been drawn, so that you can safely draw a new line:

    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        Pen pen1 = new System.Drawing.Pen(Color.Black, 3);
        Pen pen2 = new System.Drawing.Pen(panel1.BackColor, 3);
        Graphics g = panel1.CreateGraphics();
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        // Clear the graphics, creating a blank area to draw on
        g.Clear(panel1.BackColor);
        g.DrawLine(pen1, new Point(0, 0), new Point(e.Location.X, e.Location.Y));
        x_previous = e.Location.X;
        y_previous = e.Location.Y;
    }
    

    Hope this helps!

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

Sidebar

Related Questions

Say I want to draw a line, then wait five seconds, then draw another
I am new to iPad programming. I want to draw line graph in iPad.
I am new to core Plot framework. I want to draw line graph and
I want to draw line on image view then image view is to put
I want to draw a line consisting of multiple points via mouse click in
i want to draw line, i have two textfiled in which i enter some
I want to draw line on UIImageView. I already draw line on UIImageView but
I want to Draw multiple line Graph with each line have different color and
I want to draw a line in Crystal report. I can do that from
I want to draw this in my view to draw this line, I have

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.