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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:49:09+00:00 2026-06-15T23:49:09+00:00

Inside the Paint event for panel, I have a code, that should draw a

  • 0

Inside the Paint event for panel, I have a code, that should draw a blue line between 2 points.

        private void panel1_Paint(object sender, PaintEventArgs e)
    {
        panel1.AllowDrop = true;
        listBox1.AllowDrop = true;
        if (!s.IsEmpty && !f.IsEmpty)
        {

            e.Graphics.DrawLine(new Pen(Color.Blue, 5f), f, s);
            s = Point.Empty;
            f = Point.Empty;

        }

    }

Im Invalidating the panel in SetPoint method:

     void setPoint(Point p)
    {
        if (f.IsEmpty)
            f = p;
        else
        {
            s = p;
            panel1.Invalidate();
        }


    }

That is triggered by clicking on a button.
It will draw a line, but the problem is, that when one line already exists. It will overwrite it. I thought problem is in Invalidate. But I dont know how to fix it because Refresh() or Update() Doesn’t work.

What I’m doing wrong?

  • 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-15T23:49:10+00:00Added an answer on June 15, 2026 at 11:49 pm

    You need to save all your points in some structure.
    In Paint method you will loop through the structure and draw all the lines.

    That’s because when Paint is activated it redraws all the control once again, and it can’t “remember” what was there before, it is only doing what you wrote inside.

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

Sidebar

Related Questions

I have the code that draw a point inside a polygon. Each time I
i have such problem that jQuery onclick event dont see click on link inside
I am beginner in rails. I have view that i try to print inside
I need to paint the line which links two points. I am doing it,
If I have a class with a couple of event handlers inside of it
I am rendering stuff with a Graphics-object in a picturebox inside the Paint-event for
I have the below code, which works, to draw a border around a control
I have an application that requires zoom inside a ScrollPane, but with my current
I would like to animate a blue box inside a panel, using a wxTimer.
I have GridView and Button controls nested inside a Panel . <asp:Panel ID=PanelPopUp runat=server>

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.