I’m currently trying to make a simple paint program in C# using a Windows Forms Application. When converting my list of Points to an Array using the ToArray function, I’m getting a generic “ArgumentException was unhandled: Parameter is invalid” error. I know I’ve done this before and it’s worked fine, is there something special about the DrawLines function that I’m not aware of? Below is the code, with the line in question being the last line in the panel1_Paint event. Thanks in advance for any help you can provide.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GetSig
{
public partial class Form1 : Form
{
bool paint = false;
List<Point> myPointList = new List<Point>();
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
paint = true;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (paint)
{
myPointList.Add(e.Location);
panel1.Invalidate();
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
paint = false;
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLines(Pens.Black, myPointList.ToArray());
}
}
}
Well, you can’t draw lines without at least two points 🙂