简体   繁体   English

如何将面板的内容复制到richTextBox?

[英]How can I copy the contents of a Panel to a richTextBox?

I have a Panel which the user of the application. 我有一个应用程序的用户面板。 The panel allows the user to enter their signature digitally. 该面板允许用户以数字方式输入其签名。 I would like to take the drawing from the panel and copy it to the very end of the richTextBox. 我想从面板上获取图形并将其复制到richTextBox的末尾。

My current code for the panel is as follows: 我当前的面板代码如下:

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();
    }
}

} }

How can I take the drawing from the Panel and insert it to the end of the richTextBox? 如何从面板上获取图形并将其插入到richTextBox的末尾?

You could first draw the signature to the Bitmap and then copy that bitmap through Clipboard into RichTextBox . 您可以先将签名绘制到位Bitmap ,然后通过Clipboard将该位图复制到RichTextBox You could try this but I must say that it is not tested: 您可以尝试这样做,但我必须说,它尚未经过测试:

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();

Or alternatively, you could draw Lines into the Bitmap 或者,您可以将Lines绘制Lines Bitmap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM