如何打印表单的特定区域?
我的应用程序显示分组的线性数据。该表示相当简单。 UI 分为几个 GroupBox,其中数据通过 TextBox 和 Labels 显示。
现在,我想以一种简单的方式打印数据。我的想法是仅打印 GroupBox 并调整对齐方式,以便打印的页面看起来更好一些。
对于 WinForms 可以推荐哪些方法或者是否有最佳实践?是否存在任何预定义的帮助程序类?
My applications displays grouped linear data. The representation is fairly simple. The UI is divided into a few GroupBoxes in which data is displayed by TextBoxes and Labels.
Now, I'd like to print the data in a simple way. My idea is to print only the GroupBoxes and adjust the alignment so that the printed page looks a bit nicer.
What approaches can be recommended for WinForms or is there a best practice? Do there exist any predefined helper classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Control.DrawToBitmap()
方法为控件生成图像,您可以使用e 在
。PrintDocument.PrintPage
事件处理程序中将其绘制到纸张上.Graphics.DrawImage()从长远来看,这并不是一个“最佳实践”。打印机的分辨率远远高于显示器。通常为每英寸 600 点与 96 点。为了避免控件变成邮票,您必须将位图重新缩放 6 倍。
PrintDocument
类默认执行此操作。结果是颗粒状的,尤其是在通常的距离处查看时,文本看起来很糟糕。您只能使用Graphics.DrawString()
获得美观的文本。换句话说,编写代码而不是复制位图。有很多可用的报告生成器可以帮助您避免编写代码的乏味。You can use the
Control.DrawToBitmap()
method to generate an image for the control, Which you can draw to paper in yourPrintDocument.PrintPage
event handler withe.Graphics.DrawImage()
.This is not a 'best practice' by a long shot. Printers have a resolution far greater than monitors. Typically 600 dots per inch versus 96. To avoid getting the controls turned into postage stamps you have to rescale the bitmaps by a factor of 6. The
PrintDocument
class does so by default. The result is grainy, especially text looks poorly when viewed at a typical arm's length. You'll only get good looking text withGraphics.DrawString()
. In other words, write code instead of copying bitmaps. There are plenty of report generators available that help you avoid the tedium of writing the code.一种更简单的方法是使用 Visual Basic PowerPack 的 PrintForm 组件。只需在 VS 的工具箱中找到 PrintForm 组件并将其拖到表单表面即可。就这样。
An easier way is to use the PrintForm component of the Visual Basic PowerPacks. Simply locate in the Toolbox in VS the PrintForm component and drag it onto the surface of your form. Thats all.