c# - 在 C# 中将点列表转换为数组

标签 c# winforms list paint

我目前正在尝试使用 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());
    }
}
}

最佳答案

根据MSDN :

The first two points in the array specify the first line.

您的数组中至少需要两个点。

关于c# - 在 C# 中将点列表转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14980243/

相关文章:

c# - 在任务栏中运行 winform

c# - Entity Framework .load(MergeOption) 做什么?

c# - 在 C# Windows 中更改文本框中的光标位置

c# - TextBox 可以显示的最大字符数

C# - EventHandler 始终为空

class - 关于 Clojure 中的列表和其他内容的问题

c# - 从 IEnumerable 转换为 IEnumerable<object>

c# - 为什么 RichTextBox 在文档开始之前总是包含额外的字符?

java - 将整数数组添加到 ArrayList<int[]>

python - 从 Python 中的对象列表中删除对象的最快或最惯用的方法