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);
}
}
}