1

我正在使用此代码使用鼠标指针在 WinForm 中的面板上绘图。

public partial class Signature : Form
{
    SolidBrush color;
    List<List<Point>> _lines;
    Boolean _mouseDown;

    public Signature()
    {
        InitializeComponent();
        _lines = new List<List<Point>>();
        color = new SolidBrush(Color.Black);
        _mouseDown = false;
    }

    private void clear_Click(object sender, EventArgs e)
    {
        _lines.Clear();
        panel1.Invalidate();
    }

    private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
        _mouseDown = true;
        _lines.Add(new List<Point>());
    }


    private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
        if (_mouseDown)
        {
            _lines.Last().Add(e.Location);
            panel1.Invalidate();

        }
    }

    private void panel1_Paint(object sender, PaintEventArgs e)
    {
        foreach (var lineSet in _lines)
        {
            if (lineSet.Count > 1)
            {
                e.Graphics.DrawLines(new Pen(color), lineSet.ToArray());
            }
        }
    }
    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
        _mouseDown = false;
    }
}

}

我对编程很陌生,所以如果这是一个愚蠢的问题,请原谅我。我不知道如何使绘制的线条更粗一些。有人可以帮助我吗?

4

1 回答 1

3

而不是new Pen(color)你可以使用new Pen(color, floatWidth)

示例可以在这里找到

于 2013-04-24T21:00:39.100 回答