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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:32:27+00:00 2026-05-16T08:32:27+00:00

How can I put my created graphic codes on the paint event? I’m having

  • 0

How can I put my created graphic codes on the paint event?
I’m having troubles displaying It to the paint. I tried to add Points to a List but the lines I have drawn are merging.
Help!

Here’s the code:

private Point _ps = new Point();
private Point _pe = new Point();
private TransparentPanel _thispan;
private Rectangle _SelectRect;
private Graphics _g;
private Pen _pen;
List<Point> _listPS = new List<Point>();
List<Point> _listPE = new List<Point>();

private void _newTransPan_MouseDown(object sender, MouseEventArgs e)
{
    _SelectRect.Width = 0;
    _SelectRect.Height = 0;
    _SelectRect.X = e.X;
    _SelectRect.Y = e.Y;

    _ps.X = e.X;
    _ps.Y = e.Y;
    _pe = _ps;
}

private void _newTransPan_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        _thispan = (TransparentPanel)sender;

        ControlPaint.DrawReversibleLine(_thispan.PointToScreen(_ps),  _thispan.PointToScreen(_pe), Color.Red);
        _pe = new Point(e.X, e.Y);
        ControlPaint.DrawReversibleLine(_thispan.PointToScreen(_ps), _thispan.PointToScreen(_pe), Color.Red);
    }
}

private void _newTransPan_MouseUp(object sender, MouseEventArgs e)
{

    _thispan = (TransparentPanel)sender;

    _g = _thispan.CreateGraphics();
    _flagCol = _mdt._getColorVal();
    _pen = new Pen(_flagCol, _mdt._getPenVal());
    _pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
    _pen.DashCap = System.Drawing.Drawing2D.DashCap.Triangle;
    ControlPaint.DrawReversibleLine(_thispan.PointToScreen(_ps), _thispan.PointToScreen(_pe), Color.Red);
     _g.DrawLine(_pen, _ps, _pe);

     _listPS.Add(_ps);
     _listPE.Add(_pe);

 }

private void _newTransPan_Paint(object sender, PaintEventArgs e)
{
    _thispan = (TransparentPanel)sender;
    _g = _thispan.CreateGraphics();

    foreach (Point _tps in _listPS)
    {
        foreach (Point _tpe in _listPE)
        {
           _g.DrawLine(_pen, _tps, _tpe);
        }
    }
}
  • 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-16T08:32:28+00:00Added an answer on May 16, 2026 at 8:32 am

    In your _newTransPan_Paint event handler, you are connecting every start point with every end point. Of course this won’t produce a continuous segmented line; it’ll produce a scribble. You want to connect each start point only with its corresponding end point:

    private void _newTransPan_Paint(object sender, PaintEventArgs e)
    {
        var g = _newTransPan.CreateGraphics();
    
        for (int i = 0; i < _listPS.Count; i++)
            g.DrawLine(_pen, _listPS[i], _listPE[i]);
    }
    

    Once again, I would like to stress that you should use local variables. You will create yourself difficult-to-find bugs later if you don’t. There is a reason local variables exist; use them whenever you can, and use fields only if you need to. In your code:

    • _g and _pen should be local variables. You are assigning a new value to them in every method, so there is no data sharing going on.

    • If I’m not mistaken, you already have _newTransPan for your panel, so _thispan is redundant. You can probably remove it entirely and replace all occurrences of it with _newTransPan.

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

Sidebar

Related Questions

No related questions found

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.