home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic .NET - Read Less - Learn More / Visual_Basic.NET_Read_Less_Learn_More_Richard_Bowman_Visual_2002.iso / Resources / Code / Ch5-UsingPrintDocument / Form1.vb < prev   
Text File  |  2001-07-20  |  3KB  |  85 lines

  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.     Private PageNumber As Integer
  4.  
  5. #Region " Windows Form Designer generated code "
  6.  
  7.     Public Sub New()
  8.         MyBase.New()
  9.  
  10.         'This call is required by the Windows Form Designer.
  11.         InitializeComponent()
  12.  
  13.         'Add any initialization after the InitializeComponent() call
  14.  
  15.     End Sub
  16.  
  17.     'Form overrides dispose to clean up the component list.
  18.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  19.         If disposing Then
  20.             If Not (components Is Nothing) Then
  21.                 components.Dispose()
  22.             End If
  23.         End If
  24.         MyBase.Dispose(disposing)
  25.     End Sub
  26.     Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
  27.     Friend WithEvents Button1 As System.Windows.Forms.Button
  28.  
  29.     'Required by the Windows Form Designer
  30.     Private components As System.ComponentModel.Container
  31.  
  32.     'NOTE: The following procedure is required by the Windows Form Designer
  33.     'It can be modified using the Windows Form Designer.  
  34.     'Do not modify it using the code editor.
  35.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  36.         Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument()
  37.         Me.Button1 = New System.Windows.Forms.Button()
  38.         Me.SuspendLayout()
  39.         '
  40.         'PrintDocument1
  41.         '
  42.         Me.PrintDocument1.DocumentName = "MyDoc"
  43.         '
  44.         'Button1
  45.         '
  46.         Me.Button1.Location = New System.Drawing.Point(96, 64)
  47.         Me.Button1.Name = "Button1"
  48.         Me.Button1.Size = New System.Drawing.Size(120, 48)
  49.         Me.Button1.TabIndex = 0
  50.         Me.Button1.Text = "Button1"
  51.         '
  52.         'Form1
  53.         '
  54.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  55.         Me.ClientSize = New System.Drawing.Size(292, 273)
  56.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
  57.         Me.Name = "Form1"
  58.         Me.Text = "Form1"
  59.         Me.ResumeLayout(False)
  60.  
  61.     End Sub
  62.  
  63. #End Region
  64.  
  65.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  66.         PrintDocument1.Print()
  67.  
  68.     End Sub
  69.  
  70.     Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  71.         Dim gr As Graphics = e.Graphics
  72.  
  73.         Dim red As New Pen(Drawing.Color.Red)
  74.         gr.DrawLine(red, e.MarginBounds.Left, e.MarginBounds.Top, _
  75.             e.MarginBounds.Right, e.MarginBounds.Bottom)
  76.  
  77.         PageNumber += 1
  78.         If PageNumber Mod 2 Then
  79.             e.HasMorePages = False
  80.         Else
  81.             e.HasMorePages = True
  82.         End If
  83.     End Sub
  84. End Class
  85.