我目前正在尝试使用 Windows 窗体应用程序在 C# 中制作一个简单的绘画程序。使用 ToArray 函数将点列表转换为数组时,出现通用“ArgumentException 未处理:参数无效”错误。我知道我之前已经这样做过并且效果很好,DrawLines 函数有什么我不知道的特别之处吗?下面是代码,其中有问题的行是 panel1_Paint 事件中的最后一行。预先感谢您提供的任何帮助。
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());
}
}
}
最佳答案
关于c# - 在 C# 中将点列表转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14980243/