我刚刚创建了一个请求零件的数据库应用程序。
它有几种形式,一种用于请求者,一种用于主管批准,一种用于采购批准,另一种供职员用来了解要订购什么。
现在我是无纸化的忠实拥护者,但我的雇主真的很喜欢他们的纸张。 有没有一种简单的方法可以将我的 Windows 窗体复制到纸上所见即所得?
我还应该补充一点,我只能使用 2.0 .Net 框架
谢谢
最佳答案
这是一个快速的方法。您可以清理代码以使其适合您的需要:
public static class FormExtensions
{
public static void PrintForm(this Form f)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += (o, e) =>
{
Bitmap image = new Bitmap(f.ClientRectangle.Width, f.ClientRectangle.Height);
f.DrawToBitmap(image, f.ClientRectangle);
e.Graphics.DrawImage(image, e.PageBounds);
};
doc.Print();
}
}
这会将表单拉伸(stretch)到页面大小。如果需要,您可以调整 DrawImage 方法调用的第二个参数以将其绘制在其他地方。
关于c# - 有没有一种简单的方法可以打印出我的点网 Windows 窗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/635627/