I'm working on an app where I need to draw lines on Canvas, these lines need to be in an array so I can still add changes to it (Resizeable and color). I'm trying to build a paint-like function.
This is my code
private void w_Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (isDrawing)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
//lineStartPoint = e.GetPosition(w_Canvas);
//Thread.Sleep(2);
Line[] l = new Line[999999];
for (int d = 0; d < 999999; d++)
{
Point lineStartPoint = e.GetPosition(w_Canvas);
l[d].X1 = lineStartPoint.X;
l[d].Y1 = lineStartPoint.Y;
Thread.Sleep(1);
Point lineEnd = e.GetPosition(w_Canvas);
l[d].X2 = lineEnd.X;
l[d].Y2 = lineEnd.Y;
l[d].Stroke = brush;
l[d].StrokeThickness = 3;
//lineStartPoint = lineEnd;
//probeert ee nproperty the accessen warvan de property 0 is
}
DrawLines(l);
}
}
}
private void DrawLines(Line[] l)
{
foreach (Line line in l)
{
w_Canvas.Children.Add(line);
}
}
private void w_Canvas_MouseUp(object sender, MouseButtonEventArgs e)
{
isDrawing = false;
}
Currently I'm getting a 'System.NullReferenceException' where an object reference isn't installed on a copy of an object.