Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2015. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Text Editor
- '
- ' Author: Joseph L. Bolen
- ' Date Created: Feb 2015
- '
- ' Description: Simple plain text editor program with printing ability.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/TzWs9kO
- ' App's screen design time specs at: http://pastebin.com/bhinRQ5d
- ' App's Visual Basic .NET Event Procedures & TODO's is at
- ' http://pastebin.com/UZ4tcEpE
- ' App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Imports System.Drawing.Printing
- ' File Print option
- Private Sub PrintToolStripMenuItem_Click(sender As Object, e As EventArgs) _
- Handles PrintToolStripMenuItem.Click, PrintToolStripButton.Click
- Try
- PrintDocument1.Print()
- Catch ex As InvalidPrinterException
- MessageBox.Show(ex.Message, "Invalid Printer",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error)
- Catch ex As Exception
- MessageBox.Show("There was a problem printing the file." &
- ControlChars.NewLine & ex.Message,
- "Printing File Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error)
- End Try
- End Sub
- ' Print each page of document, one page at a time.
- Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) _
- Handles PrintDocument1.PrintPage
- ' Set up actual output to print.
- Static pageNumber As Integer = 1
- Dim leftMargin As Integer
- Dim topMargin As Integer
- Dim printableAreaWidth As Integer
- Dim printableAreaHeight As Integer
- Dim hdrLeft As Integer
- Dim hdrRight As Integer
- Dim hdrFont As New Font("Ariel", 14)
- Dim dtlFont As New Font("Tahoma", 24)
- Dim dtlBrush As New SolidBrush(Color.Navy)
- ' Determine printable area
- With Me.PrintDocument1.DefaultPageSettings
- If .Landscape Then
- topMargin = .Margins.Top
- leftMargin = .Margins.Left
- printableAreaWidth = (.PaperSize.Height - (.Margins.Left + .Margins.Right))
- printableAreaHeight = (.PaperSize.Width - (.Margins.Top + .Margins.Bottom))
- hdrLeft = 50
- hdrRight = .PaperSize.Height - 145
- Else
- ' Portrait
- topMargin = .Margins.Top
- leftMargin = .Margins.Left
- printableAreaWidth = (.PaperSize.Width - (.Margins.Left + .Margins.Right))
- printableAreaHeight = (.PaperSize.Height - (.Margins.Top + .Margins.Bottom))
- hdrLeft = 50
- hdrRight = .PaperSize.Width - 145
- End If
- End With
- ' Draw a red boarder. Activate for testing only.
- e.Graphics.DrawRectangle(New Pen(Brushes.Red, 3), e.MarginBounds)
- ' Setup Print Header - Filename and Page Number.
- Dim headerTitle As String = "Text Editor Test Printing"
- ' Setup Print Body
- Dim fmt = New StringFormat(StringFormatFlags.NoWrap)
- fmt.Trimming = StringTrimming.EllipsisWord
- Dim linesperpage As Integer = CInt(Math.Round(printableAreaHeight / (dtlFont.Height + 0.025)))
- ' Page Header
- e.Graphics.DrawString(headerTitle, hdrFont, Brushes.Black, hdrLeft, 50)
- e.Graphics.DrawString("Page " & pageNumber.ToString(), hdrFont, Brushes.Black, hdrRight, 50)
- ' Page Body
- For line = 0 To (linesperpage - 1)
- e.Graphics.DrawString("This is line " & (line + 1).ToString & " of the document.",
- dtlFont,
- dtlBrush,
- New RectangleF(leftMargin, topMargin + dtlFont.Height * (line), printableAreaWidth, dtlFont.Height),
- fmt)
- Next
- pageNumber += 1
- If (pageNumber < 1) Then
- e.HasMorePages = True
- Else
- e.HasMorePages = False
- pageNumber = 1
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment