打印本文 打印本文 关闭窗口 关闭窗口
用vb.net实现写字板程序报告(四)完
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2921  更新时间:2009/4/23 19:01:53  文章录入:mintao  责任编辑:mintao
 

        '''' Instantiate the StringFormat class, which encapsulates text layout

        '''' information (such as alignment and line spacing), display manipulations

        '''' (such as ellipsis insertion and national digit substitution) and OpenType

        '''' features. Use of StringFormat causes MeasureString and DrawString to use

        '''' only an integer number of lines when printing each page, ignoring partial

        '''' lines that would otherwise likely be printed if the number of lines per

        '''' page do not divide up cleanly for each page (which is usually the case).

        '''' See further discussion in the SDK documentation about StringFormatFlags.

        Dim fmt As New StringFormat(StringFormatFlags.LineLimit)

        '''' Call MeasureString to determine the number of characters that will fit in

        '''' the printing area rectangle. The CharFitted Int32 is passed ByRef and used

        '''' later when calculating intCurrentChar and thus HasMorePages. LinesFilled

        '''' is not needed for this sample but must be passed when passing CharsFitted.

        '''' Mid is used to pass the segment of remaining text left off from the

        '''' previous page of printing (recall that intCurrentChar was declared as

        '''' static.

        Dim intLinesFilled, intCharsFitted As Int32

        e.Graphics.MeasureString(Mid(rtbox.Text, intCurrentChar + 1), font, _

                    New SizeF(intPrintAreaWidth, intPrintAreaHeight), fmt, _

                    intCharsFitted, intLinesFilled)

 

        '''' Print the text to the page.

        e.Graphics.DrawString(Mid(rtbox.Text, intCurrentChar + 1), font, _

            Brushes.Black, rectPrintingArea, fmt)

 

        '''' Advance the current char to the last char printed on this page. As

        '''' intCurrentChar is a static variable, its value can be used for the next

        '''' page to be printed. It is advanced by 1 and passed to Mid() to print the

        '''' next page (see above in MeasureString()).

        intCurrentChar += intCharsFitted

 

        '''' HasMorePages tells the printing module whether another PrintPage event

        '''' should be fired.

        If intCurrentChar < rtbox.Text.Length Then

            e.HasMorePages = True

        Else

            e.HasMorePages = False

            '''' You must explicitly reset intCurrentChar as it is static.

            intCurrentChar = 0

        End If

    End Sub

 

    Private Sub printpreview()

        Dim ppd As New PrintPreviewDialog()

        Try

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口