2

我有一个面板,它是应用程序的用户。该面板允许用户以数字方式输入他们的签名。我想从面板中取出绘图并将其复制到richTextBox 的最末端。

我当前的面板代码如下:

public partial class Signature : Form
{
    SolidBrush color;
    float width;
    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();
        sign.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);
            sign.Invalidate();

        }
    }

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

    private void use_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Signature successfully imported!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        Basic_Word_Processor.Instance.richTextBoxPrintCtrl1.SelectedText = "";
        this.Close();
    }
}

}

如何从 Panel 中获取绘图并将其插入到 RichTextBox 的末尾?

4

1 回答 1

1

您可以先将签名绘制到Bitmap,然后将该位图复制ClipboardRichTextBox. 你可以试试这个,但我必须说它没有经过测试:

Bitmap bmp = new Bitmap(panel1.Width, panel1.Height);
Rectangle rect = new Rectangle(0, 0, panel1.Width, panel1.Height);
panel1.DrawToBitmap(bmp, rect);
Clipboard.SetImage(bmp);
richTextBox1.Paste();

或者,您可以绘制LinesBitmap

于 2013-04-24T22:40:48.177 回答