PrintDocument和模糊的UserControls ...需要帮助. [英] PrintDocument and blurry UserControls... Need help please.

查看:70
本文介绍了PrintDocument和模糊的UserControls ...需要帮助.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我想打印出带有一些带有文本和图形的自定义UserControl的页面.

I want to print out a page with some custom UserControls with text and graphics.

我使用UserControls是因为我可以完全按照我希望它们在纸上显示的方式进行设计.

I use UserControls because I can design exactly as I want them to show on paper.

所以我在运行时在内存中有一些UserControl,然后用 .DrawToBitmap ,然后使用 DrawImageUnscaled .

So I've got some UserControls in memory at runtime, then I draw them on Bitmap objects with .DrawToBitmap, and then draw the resulting bitmaps in PrintDocument's PrintPage Event, using DrawImageUnscaled.

这是完整的示例,因此任何人都可以快速测试我在做什么:

->测试用户控件:

Here's the complete example, so anyone can test quickly what I'm doing :

--> The Test UserControl :

Public Class TestUserControl

    Protected Overrides Sub OnPrint(ByVal e As System.Windows.Forms.PaintEventArgs)

        Dim P As New Pen(Color.DimGray, 1)

        MyBase.OnPrint(e)

        'Print Borders
        With Me
            e.Graphics.DrawRectangle(P, 0, 0, .Width - 1, .Height - 1)
        End With
        For Each C As Control In Me.Controls
            With C
                e.Graphics.DrawRectangle(P, .Left, .Top, .Width - 1, .Height - 1)
            End With
        Next

    End Sub

End Class

->表单,带有按钮:

Public Class Form1

    Private mPrinterName As String = "My Printer Name"
    Private WithEvents mPD As Printing.PrintDocument

    Private Sub btn_test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_test.Click

        'PrintDocument Settings
        mPD = New Printing.PrintDocument
        With mPD
            .DefaultPageSettings.PaperSize = New Printing.PaperSize("Custom", 827, 1169)
            .PrinterSettings.PrinterName = mPrinterName
            .DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
        End With

        'Preview
        Dim PPD As New PrintPreviewDialog
        PPD.Document = mPD
        PPD.ShowDialog()

    End Sub

    Private Sub mPD_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mPD.PrintPage

        'Graphics Settings
        With e.Graphics
            .CompositingQuality = Drawing2D.CompositingQuality.HighQuality
            .InterpolationMode = Drawing2D.InterpolationMode.High
            .PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
            .SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        End With

        'Print some test UserControls ...
        For i As Integer = 1 To 3
            Dim C As New TestUserControl
            Dim bmpC As New Bitmap(C.Width, C.Height)
            C.DrawToBitmap(bmpC, New Rectangle(0, 0, C.Width, C.Height))
            e.Graphics.DrawImageUnscaled(bmpC, 50, i * 250)
        Next

        e.HasMorePages = False

    End Sub

End Class

TestUserControl上带有一些带有文本的标签.
Overrides Sub OnPrint()会强制绘制矩形,因为如果我在内存中创建这些UserControl而不将其放在容器控件上,则不会打印出边框.

The TestUserControl has some labels with text on it.
The Overrides Sub OnPrint() forces the drawing of rectangles, because if I create these UserControls in memory without putting them on a container control, the borders aren't printed out.

您可以看到,我已经根据高质量输出对 e.Graphics 进行了所有设置,或者我认为应该如此,但是对于文本和行,输出仍然是模糊的:am我缺少某些特殊的质量设置吗?如何打印用户控件 可以说是最高质量,就像我在显示屏上看到的那样?

As you can see I've put all settings for e.Graphics according to a High Quality output, or so I think it should be, but output is still blurry for texts and lines : am I missing some particular quality setting ? How to print a UserControl at it's maximum quality, let's say, as I see it on the display ?

感谢任何能够提供帮助的人.

Thanks to anyone able to help.


推荐答案

如何以最高质量打印UserControl,"

"How to print a UserControl at it's maximum quality,"

使用GDI +矢量绘图语句和DrawString呈现控件.避免使用DrawImage.

Render the controls using GDI+ vector drawing statements and DrawString.  Avoid using DrawImage.


这篇关于PrintDocument和模糊的UserControls ...需要帮助.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆