【问题标题】:How can I copy the contents of a Panel to a richTextBox?如何将 Panel 的内容复制到 RichTextBox?
【发布时间】:2013-04-18 16:06:32
【问题描述】:

我有一个应用程序用户的面板。该面板允许用户以数字方式输入他们的签名。我想从面板中取出绘图并将其复制到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 的末尾?

【问题讨论】:

    标签: c# winforms visual-studio richtextbox panel


    【解决方案1】:

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

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

    或者,您可以将Lines 绘制到Bitmap

    【讨论】:

    • 可以根据我的需要进行调整。谢谢!
    猜你喜欢
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多