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