Wrapped Printing : Print Document « GUI « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » GUI » Print Document 




Wrapped Printing
  
Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports System.Drawing

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.cmdPrintWrapped = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.cmdPrint = New System.Windows.Forms.Button
        Me.txtData = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        Me.cmdPrintWrapped.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cmdPrintWrapped.Location = New System.Drawing.Point(210174)
        Me.cmdPrintWrapped.Name = "cmdPrintWrapped"
        Me.cmdPrintWrapped.Size = New System.Drawing.Size(10424)
        Me.cmdPrintWrapped.TabIndex = 7
        Me.cmdPrintWrapped.Text = "Print Wrapped"
        '
        Me.Label1.Location = New System.Drawing.Point(1410)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(16416)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "Text To Print:"
        '
        'cmdPrint
        '
        Me.cmdPrint.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.cmdPrint.Location = New System.Drawing.Point(14174)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(10424)
        Me.cmdPrint.TabIndex = 5
        Me.cmdPrint.Text = "Print Unwrapped"
        '
        'txtData
        '
        Me.txtData.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom_
                    Or System.Windows.Forms.AnchorStyles.Left_
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtData.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtData.Location = New System.Drawing.Point(1430)
        Me.txtData.Multiline = True
        Me.txtData.Name = "txtData"
        Me.txtData.ReadOnly = True
        Me.txtData.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtData.Size = New System.Drawing.Size(300132)
        Me.txtData.TabIndex = 4
        Me.txtData.Text = resources.GetString("txtData.Text")
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(329212)
        Me.Controls.Add(Me.cmdPrintWrapped)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.cmdPrint)
        Me.Controls.Add(Me.txtData)
        Me.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "Form1"
        Me.Text = "Wrapped Printing"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents cmdPrintWrapped As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents cmdPrint As System.Windows.Forms.Button
    Friend WithEvents txtData As System.Windows.Forms.TextBox

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdPrint.Click
        Dim MyDoc As New PrintDocument()
        AddHandler MyDoc.PrintPage, AddressOf UnWrappedPrint

        Dim dlgSettings As New PrintDialog()
        dlgSettings.Document = MyDoc

        Dim Result As DialogResult
        Result = dlgSettings.ShowDialog()

        If Result = DialogResult.OK Then MyDoc.Print()
    End Sub


    Private Sub cmdPrintWrapped_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles cmdPrintWrapped.Click
        Dim MyDoc As New PrintDocument()
        AddHandler MyDoc.PrintPage, AddressOf WrappedPrint

        Dim dlgSettings As New PrintDialog()
        dlgSettings.Document = MyDoc

        Dim Result As DialogResult
        Result = dlgSettings.ShowDialog()

        If Result = DialogResult.OK Then MyDoc.Print()
    End Sub

    Private Sub UnWrappedPrint(ByVal sender As Object, ByVal e As PrintPageEventArgs)
        Dim MyFont As New Font("Verdana"16)
        Dim As Single = e.MarginBounds.Left
        Dim As Single = e.MarginBounds.Top
        e.Graphics.DrawString(txtData.Text, MyFont, Brushes.Black, x, y)
    End Sub
    Private Sub WrappedPrint(ByVal sender As Object, ByVal e As PrintPageEventArgs)
        Dim MyFont As New Font("Verdana"16)
        Dim As Single = e.MarginBounds.Left
        Dim As Single = e.MarginBounds.Top
        e.Graphics.DrawString(txtData.Text, MyFont, Brushes.Black, e.MarginBounds, StringFormat.GenericDefault)
    End Sub
    Private Sub WrappedPrint2(ByVal sender As Object, ByVal e As PrintPageEventArgs)
        Dim MyFont As New Font("Verdana"16)
        Dim LineHeight As Single = MyFont.GetHeight(e.Graphics)
        Dim As Single = e.MarginBounds.Left
        Dim As Single = e.MarginBounds.Top

        Dim Line As String
        Dim ParsedLines As New ArrayList()
        Dim TextToPrint As String = txtData.Text

        Dim As Integer
        Do
            Line &= TextToPrint.Chars(0)
            TextToPrint = TextToPrint.Substring(1)

            If Line.EndsWith(" "Then
                If e.Graphics.MeasureString(Line, MyFont).Width > (e.PageBounds.Width - 300Then
                    ParsedLines.Add(Line)
                    Line = ""
                End If
            End If
        Loop While TextToPrint <> ""
        ParsedLines.Add(Line)

        For Each Line In ParsedLines
            e.Graphics.DrawString(Line, MyFont, Brushes.Black, x, y)
            y += LineHeight
        Next

    End Sub

End Class

   
    
  














Related examples in the same category
1.Assign Bmp file to a Print DocumentAssign Bmp file to a Print Document
2.Print Test
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.