[英]How to print a winforms usercontrol
I've created a winforms usercontrol doing a lot of custom painting in the OnPaint event. 我创建了一个winforms用户控件,它在OnPaint事件中进行了大量自定义绘制。 Now I would like to print this control.
现在,我想打印此控件。
or 要么
In PrintPage event aquire image of control, and draw it to printer graphics. 在PrintPage事件中,获取控件的图像,并将其绘制到打印机图形上。
private void PrintPageEventHandler(object sender, PrintPageEventArgs ev) {
Rectangle rect = new Rectangle(0, 0, yourControl.Width, yourControl.Height);
//aquire image of yourControl
Bitmap bitmap = new Bitmap(yourControl.Width, yourControl.Height);
yourControl.DrawToBitmap(bitmap, rect);
ev.Graphics.DrawImage(bitmap, new Point(0, 0)); //place image on right position istead of (0, 0)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.