我目前正在嘗試使用Windows窗體應用程序在C#中進行簡單的繪圖程序。當使用ToArray函數將我的列表轉換爲數組時,我得到一個通用的「ArgumentException未處理:參數無效」錯誤。我知道我以前做過這件事,它工作得很好,有沒有什麼特別的DrawLines函數,我不知道?下面是代碼,這條線是panel1_Paint事件的最後一行。預先感謝您提供的任何幫助。將點列表轉換爲C#中的數組#
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());
}
}
}
請刪除不涉及這個問題的所有代碼。 – 2013-02-20 12:52:08
嘗試使用Point [] array = myPointList.ToArray()創建一個數組,並查看裏面的內容。也許你會發現一些奇怪的東西! – 2013-02-20 12:52:58