Option Explicit On
Option Strict On
Imports system.Drawing.Printing
Public Class Form1
Private WithEvents pd As New PrintDocument
Private sfMiddleLeft As New StringFormat
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
sfMiddleLeft.LineAlignment = StringAlignment.Center 'middle
sfMiddleLeft.Alignment = StringAlignment.Near 'left
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using PP As New PrintPreviewDialog
PP.Document = pd
PP.ShowDialog()
End Using
End Sub
Private brBlack As New SolidBrush(Color.Black)
Private pBlack As New Pen(Color.Black)
Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
With e.Graphics
For Each _Control As Control In Me.Controls 'chose your tab page here
Select Case True
Case TypeOf (_Control) Is Label
.DrawString(_Control.Text, _Control.Font, brBlack, _Control.Left, _Control.Top)
Case TypeOf (_Control) Is TextBox
.DrawRectangle(pBlack, _Control.Left, _Control.Top, _Control.Width, _Control.Height)
.DrawString(_Control.Text, _Control.Font, brBlack, New RectangleF(_Control.Left, _Control.Top, _Control.Width, _Control.Height), sfMiddleLeft)
End Select
Next
End With
End Sub
End Class