Printing with formatting in VB.NET

This is a comment thread discussing Printing with formatting in VB.NET
  • 14 years ago

    A more current version of this code along with an article and helpful discussion thread are available at the following link:

    http://www.sqlservercentral.com/columnists/jGuenther/printinginnet.asp

  • 14 years ago

    I am working on an editor in VB.net using Richtext box and I want Formatted Print/Print Preview.

    How can I use this class, can u tell me please.

  • 13 years ago

    I tried and added Italics, Font Change and Font Size. All work and will share with anyone who would like it. I did have one problem, 10pt fonts would not work. I can us 9 and below and 11 and above but not 10. If anyone has had this problem and solved it, I could use the Help

     

    Here is the new Class

    Public

    Class PrintText

    ' Inherits all the functionality of a PrintDocument

    Inherits Printing.PrintDocument

    ' Private variables to hold default font and text

    Public fntPrintFont As Font

    Private strText As String

    Dim MySplitLine As String()

    Dim varStart As Integer = 0

    Dim varChar As Integer = 0

    Public FontName As String = ""

    Public FontSize As Single = 10

    ' New constructor

    Public Sub New(ByVal Text As String)

    ' Sets the file stream

    MyBase.New()

    varStart = 0

    strText = Text

    MySplitLine = strText.Split(vbCrLf)

    End Sub

    Public Property Text() As String

    Get

    Return strText

    End Get

    Set(ByVal Value As String)

    strText = Value

    MySplitLine = strText.Split(vbCrLf)

    'Breaks up text into separate lines at Carrage Return Line Feeds

    End Set

    End Property

    Protected Overrides Sub OnBeginPrint(ByVal ev As Printing.PrintEventArgs)

    ' Run base code

    MyBase.OnBeginPrint(ev)

    ' Sets the default font

    If fntPrintFont Is Nothing Then

    fntPrintFont =

    New Font("Times New Roman", 12, FontStyle.Regular, GraphicsUnit.Point)

    End If

    End Sub

    Public Property Font() As Font