March 5th, 2009, 01:44 AM
I want to draw a line.
I use this code
But the previous line is visible.
private void OnMouseDown(object Sender, MouseEventArgs Args)
StartPoint = Args.GetPosition(DrawingCanvas);
private void OnMouseMove(object Sender, MouseEventArgs Args)
if (Args.LeftButton == MouseButtonState.Pressed)
EndPoint = Args.GetPosition(DrawingCanvas);
DrawLine(StartPoint, EndPoint, DrawingCanvas);
private void DrawLine(Point From, Point To, Canvas TargetCanvas)
CurrentLine = new Line();
CurrentLine.StrokeEndLineCap = PenLineCap.Round;
CurrentLine.StrokeStartLineCap = PenLineCap.Round;
CurrentLine.Stroke = Brushes.Red;
CurrentLine.StrokeThickness = 2.0;
CurrentLine.X1 = From.X;
CurrentLine.Y1 = From.Y;
CurrentLine.X2 = To.X;
CurrentLine.Y2 = To.Y;
How can I avoid that??
Thanks & Regards
Last edited by gstercken; April 20th, 2009 at 06:05 AM.
Reason: Added code tags
April 20th, 2009, 06:09 AM
Re: Draw Line
Well, this is sort of obvious, since it's exactly what your code does: It creates a new Line object on every MouseMove event. I guess what you intended is to create the new line in your MouseDown handler, and change only its end point when the mouse is moved?
Originally Posted by Prajeesh07
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.