前日浏览网页偶有所得,修改了一下贴了上来。 Imports System.Drawing Imports System.Drawing.Printing Public Class WinFormPrinter Class WinFormPrinter Inherits PrintDocument 'declare a variable of form Private _winForm As Form 'Const Const c_button As String = "System.Windows.Forms.Button" Const c_textbox As String = "System.Windows.Forms.TextBox" Const c_checkbox As String = "System.Windows.Forms.CheckBox" Const c_picturebox As String = "System.Windows.Forms.PictureBox" 'var Private ctl_Obj As Object Sub New()Sub New() MyBase.New() End Sub Sub New()Sub New(ByVal win As Form) _winForm = win AddHandler MyBase.PrintPage, AddressOf PrintPageHandler End Sub Private Sub PrintPageHandler()Sub PrintPageHandler(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) DrawWinForm(e.Graphics) End Sub 'Draw controls on window forms Public Sub DrawWinForm()Sub DrawWinForm(ByVal g As Graphics) Try 'Fill the drawing area with form's property(backcolor,width,height) g.FillRectangle(New SolidBrush(_winForm.BackColor), 0, 0, _winForm.Width, _winForm.Height) 'Put necessary controls into drawing area For Each ctl As Control In _winForm.Controls 'Check the type of control Select Case ctl.GetType().ToString() Case c_button ctl_Obj = CType(ctl, Button) ControlPaint.DrawButton(g, ctl_Obj.Left, ctl_Obj.Top, ctl_Obj.Width, ctl_Obj.Height, ButtonState.Normal) g.DrawString(ctl_Obj.Text _ , ctl_Obj.Font _ , New SolidBrush(ctl_Obj.ForeColor) _ , ctl_Obj.Left + ctl_Obj.Width / 2 - g.MeasureString(ctl_Obj.Text, ctl_Obj.Font).Width / 2 _ , ctl_Obj.Top + ctl_Obj.Height / 2 - g.MeasureString("a", ctl_Obj.Font).Height / 2 _ , New StringFormat) Case c_textbox ctl_Obj = CType(ctl, TextBox) ControlPaint.DrawButton(g, ctl_Obj.Left + 1, ctl_Obj.Top + 1, ctl_Obj.Width + 2, ctl_Obj.Height - 2, ButtonState.Pushed) g.DrawString(ctl_Obj.Text _ , ctl_Obj.Font _ , New SolidBrush(ctl_Obj.ForeColor) _ , ctl_Obj.Left + 2 _ , ctl_Obj.Top + ctl_Obj.Height / 2 - g.MeasureString("a", ctl_Obj.Font).Height / 2 _ , New StringFormat) Case c_checkbox ctl_Obj = CType(ctl, CheckBox) If ctl_Obj.Checked Then ControlPaint.DrawCheckBox(g, ctl_Obj.Left, ctl_Obj.Top + 1, ctl_Obj.Width, ctl_Obj.Height / 2, ButtonState.Checked) Else ControlPaint.DrawCheckBox(g, ctl_Obj.Left, ctl_Obj.Top + 1, ctl_Obj.Width, ctl_Obj.Height / 2, ButtonState.Normal) End If g.DrawString(ctl_Obj.Text _ , ctl_Obj.Font _ , New SolidBrush(ctl_Obj.ForeColor) _ , ctl_Obj.Right - ctl_Obj.Height - g.MeasureString(ctl_Obj.Text, ctl_Obj.Font).Width _ , ctl_Obj.Top _ , New StringFormat) Case c_picturebox ctl_Obj = CType(ctl, PictureBox) g.DrawImage(ctl_Obj.Image _ , New Rectangle(ctl_Obj.Left, ctl_Obj.Top, ctl_Obj.Width, ctl_Obj.Height) _ , New Rectangle(ctl_Obj.Left, ctl_Obj.Top, ctl_Obj.Width, ctl_Obj.Height) _ , GraphicsUnit.Pixel) End Select Next Catch ex As Exception Throw New Exception("Error occured at DrawWinForm(Sub):" + ex.Message) End Try End SubEnd Class