PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/VBWinFormPrinting/MainForm.vb

#
Visual Basic | 53 lines | 21 code | 10 blank | 22 comment | 0 complexity | 3a6cdf346fe400b10e7a929367444e6f MD5 | raw file
  1. '************************************* Module Header **************************************\
  2. ' Module Name: MainForm.vb
  3. ' Project: VBWinFormPrinting
  4. ' Copyright (c) Microsoft Corporation.
  5. '
  6. ' The Printing sample demonstrates how to do standard print job in Windows Forms Application.
  7. '
  8. ' This source is subject to the Microsoft Public License.
  9. ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  10. ' All other rights reserved.
  11. '
  12. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  13. ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  14. ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  15. '******************************************************************************************/
  16. Public Class MainForm
  17. Inherits Form
  18. Public Sub New()
  19. MyBase.New()
  20. InitializeComponent()
  21. End Sub
  22. Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  23. ' The example assumes your form has a Button control,
  24. ' a PrintDocument component named myDocument,
  25. ' and a PrintPreviewDialog control.
  26. ' Handle the PrintPage event to write the print logic.
  27. AddHandler PrintDocument1.PrintPage, AddressOf Me.printDocument1_PrintPage
  28. ' Specify a PrintDocument instance for the PrintPreviewDialog component.
  29. Me.PrintPreviewDialog1.Document = Me.PrintDocument1
  30. End Sub
  31. Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  32. ' Specify what to print and how to print in this event handler.
  33. ' The follow code specify a string and a rectangle to be print
  34. Dim f As Font = New Font("Vanada", 12)
  35. Dim br As SolidBrush = New SolidBrush(Color.Black)
  36. Dim p As Pen = New Pen(Color.Black)
  37. e.Graphics.DrawString("This is a text.", f, br, 50, 50)
  38. e.Graphics.DrawRectangle(p, 50, 100, 300, 150)
  39. End Sub
  40. Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPrint.Click
  41. Me.PrintPreviewDialog1.ShowDialog()
  42. End Sub
  43. End Class