Imports System.Drawing.Printing
Imports System.Windows.Forms
Imports System.Drawing
_
Partial Class Form1
Inherits System.Windows.Forms.Form
_
Private Sub InitializeComponent()
Me.cmdPreviewInForm = New System.Windows.Forms.Button
Me.Preview = New System.Windows.Forms.PrintPreviewControl
Me.cmdPreview = New System.Windows.Forms.Button
Me.lblStatus = New System.Windows.Forms.Label
Me.cmdPrint = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.RadioButton4 = New System.Windows.Forms.RadioButton
Me.RadioButton5 = New System.Windows.Forms.RadioButton
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'cmdPreviewInForm
'
Me.cmdPreviewInForm.Location = New System.Drawing.Point(12, 76)
Me.cmdPreviewInForm.Name = "cmdPreviewInForm"
Me.cmdPreviewInForm.Size = New System.Drawing.Size(148, 24)
Me.cmdPreviewInForm.TabIndex = 9
Me.cmdPreviewInForm.Text = "Preview (In Form)"
'
'Preview
'
Me.Preview.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.Preview.AutoZoom = False
Me.Preview.Location = New System.Drawing.Point(180, 12)
Me.Preview.Name = "Preview"
Me.Preview.Size = New System.Drawing.Size(339, 350)
Me.Preview.TabIndex = 8
'
'cmdPreview
'
Me.cmdPreview.Location = New System.Drawing.Point(12, 44)
Me.cmdPreview.Name = "cmdPreview"
Me.cmdPreview.Size = New System.Drawing.Size(148, 24)
Me.cmdPreview.TabIndex = 7
Me.cmdPreview.Text = "Preview (Stand-alone)"
'
'lblStatus
'
Me.lblStatus.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.lblStatus.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.lblStatus.Location = New System.Drawing.Point(12, 235)
Me.lblStatus.Name = "lblStatus"
Me.lblStatus.Size = New System.Drawing.Size(148, 127)
Me.lblStatus.TabIndex = 6
'
'cmdPrint
'
Me.cmdPrint.Location = New System.Drawing.Point(12, 12)
Me.cmdPrint.Name = "cmdPrint"
Me.cmdPrint.Size = New System.Drawing.Size(148, 24)
Me.cmdPrint.TabIndex = 5
Me.cmdPrint.Text = "Print"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.RadioButton5)
Me.GroupBox1.Controls.Add(Me.RadioButton4)
Me.GroupBox1.Controls.Add(Me.RadioButton3)
Me.GroupBox1.Controls.Add(Me.RadioButton2)
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(12, 108)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(148, 111)
Me.GroupBox1.TabIndex = 10
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Zoom"
'
'RadioButton1
'
Me.RadioButton1.AutoSize = True
Me.RadioButton1.Location = New System.Drawing.Point(16, 17)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(48, 17)
Me.RadioButton1.TabIndex = 11
Me.RadioButton1.TabStop = True
Me.RadioButton1.Text = "25%"
Me.RadioButton1.UseVisualStyleBackColor = True
'
'RadioButton2
'
Me.RadioButton2.AutoSize = True
Me.RadioButton2.Location = New System.Drawing.Point(16, 34)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(48, 17)
Me.RadioButton2.TabIndex = 12
Me.RadioButton2.TabStop = True
Me.RadioButton2.Text = "50%"
Me.RadioButton2.UseVisualStyleBackColor = True
'
'RadioButton3
'
Me.RadioButton3.AutoSize = True
Me.RadioButton3.Location = New System.Drawing.Point(16, 68)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(54, 17)
Me.RadioButton3.TabIndex = 13
Me.RadioButton3.TabStop = True
Me.RadioButton3.Text = "100%"
Me.RadioButton3.UseVisualStyleBackColor = True
'
'RadioButton4
'
Me.RadioButton4.AutoSize = True
Me.RadioButton4.Location = New System.Drawing.Point(16, 85)
Me.RadioButton4.Name = "RadioButton4"
Me.RadioButton4.Size = New System.Drawing.Size(54, 17)
Me.RadioButton4.TabIndex = 14
Me.RadioButton4.TabStop = True
Me.RadioButton4.Text = "200%"
Me.RadioButton4.UseVisualStyleBackColor = True
'
'RadioButton5
'
Me.RadioButton5.AutoSize = True
Me.RadioButton5.Location = New System.Drawing.Point(16, 51)
Me.RadioButton5.Name = "RadioButton5"
Me.RadioButton5.Size = New System.Drawing.Size(48, 17)
Me.RadioButton5.TabIndex = 15
Me.RadioButton5.TabStop = True
Me.RadioButton5.Text = "75%"
Me.RadioButton5.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(531, 374)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.cmdPreviewInForm)
Me.Controls.Add(Me.Preview)
Me.Controls.Add(Me.cmdPreview)
Me.Controls.Add(Me.lblStatus)
Me.Controls.Add(Me.cmdPrint)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Text = "Print Test"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents cmdPreviewInForm As System.Windows.Forms.Button
Friend WithEvents Preview As System.Windows.Forms.PrintPreviewControl
Friend WithEvents cmdPreview As System.Windows.Forms.Button
Friend WithEvents lblStatus As System.Windows.Forms.Label
Friend WithEvents cmdPrint As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
Private WithEvents MyDoc As New PrintDocument()
Private PageNumber As Integer
Private Offset As Integer
Private PrintData(100) As String
Private Sub PrintStatus_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 100
PrintData(i) = "This is line number " & i + 1 & ". "
Next
End Sub
Private Sub cmdPrint_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles cmdPrint.Click
lblStatus.Text = ""
PageNumber = 0
Offset = 0
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 MyDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles MyDoc.PrintPage
Dim MyFont As New Font("Arial", 10)
Dim LineHeight As Single = MyFont.GetHeight(e.Graphics)
Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
PageNumber += 1
lblStatus.Text &= vbNewLine & "Sending Page " & PageNumber & " ..."
Do
e.Graphics.DrawString(PrintData(Offset), MyFont, Brushes.Black, x, y)
Offset += 1
y += LineHeight
Loop Until (y + LineHeight) > e.MarginBounds.Bottom Or Offset > PrintData.GetUpperBound(0)
If Offset < PrintData.GetUpperBound(0) Then
e.HasMorePages = True
Else
Offset = 0
lblStatus.Text &= vbNewLine & "Print or Preview Completed"
End If
End Sub
Private Sub cmdPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPreview.Click
lblStatus.Text = ""
Dim dlgPreview As New PrintPreviewDialog()
dlgPreview.Document = MyDoc
dlgPreview.Show()
End Sub
Private Sub cmdPreviewInForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPreviewInForm.Click
lblStatus.Text = ""
Preview.Zoom = 0.2
Preview.Columns = 2
Preview.Rows = 3
Preview.Document = MyDoc
Preview.InvalidatePreview()
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton4.Click, RadioButton3.Click, RadioButton2.Click, RadioButton1.Click, RadioButton5.CheckedChanged
Dim ctrl As Control = CType(sender, Control)
Preview.Zoom = Val(ctrl.Text) / 100
End Sub
End Class