print a form vb.net

rockwell

Active member
Joined
Dec 6, 2005
Messages
36
Programming Experience
Beginner
Hello all, i was wondering how do we print a form using some event in vb.net. I mean the code to print it out.

Thanks for your time ....
--kris
 
i am sorry fas but could you be more specific, you said you downloaded something right and you want to print it from a vb.net application if i am not wrong. Well can you explain your problem again clearly ....

i am sorry ...
 
It was some zip thing

i downloaded some zip thing open it
>>form utilities
lisernn mate i made a preciouse post some where all i want 2 do is print my form heres d code for d thing its jus a single page i wnt 2 print my application is a calculator thats all i want 2 print :confused:

VB.NET:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents LbResult As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents LbResult2 As System.Windows.Forms.Label
    Friend WithEvents LbTax As System.Windows.Forms.TextBox
    Friend WithEvents LbIns As System.Windows.Forms.TextBox
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents CrystalReportViewer1 As CrystalDecisions.Windows.Forms.CrystalReportViewer
    Friend WithEvents Button3 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.LbResult = New System.Windows.Forms.Label
        Me.Label9 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Button2 = New System.Windows.Forms.Button
        Me.LbResult2 = New System.Windows.Forms.Label
        Me.LbTax = New System.Windows.Forms.TextBox
        Me.LbIns = New System.Windows.Forms.TextBox
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label10 = New System.Windows.Forms.Label
        Me.CrystalReportViewer1 = New CrystalDecisions.Windows.Forms.CrystalReportViewer
        Me.Button3 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.Label1.Location = New System.Drawing.Point(8, 144)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(152, 16)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Staff ID"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.Label2.Location = New System.Drawing.Point(8, 184)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(152, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Hours Worked"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.Label3.Location = New System.Drawing.Point(8, 232)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(152, 24)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "Wage Per Hour"
        '
        'TextBox1
        '
        Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox1.ForeColor = System.Drawing.Color.Red
        Me.TextBox1.Location = New System.Drawing.Point(176, 136)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(112, 26)
        Me.TextBox1.TabIndex = 3
        Me.TextBox1.Text = "Enter"
        '
        'TextBox2
        '
        Me.TextBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox2.ForeColor = System.Drawing.Color.Red
        Me.TextBox2.Location = New System.Drawing.Point(176, 184)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(112, 26)
        Me.TextBox2.TabIndex = 4
        Me.TextBox2.Text = "View Info Bar"
        '
        'TextBox3
        '
        Me.TextBox3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox3.ForeColor = System.Drawing.Color.Red
        Me.TextBox3.Location = New System.Drawing.Point(176, 224)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(112, 26)
        Me.TextBox3.TabIndex = 5
        Me.TextBox3.Text = "View Info Bar"
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.Color.Lime
        Me.Button1.Cursor = System.Windows.Forms.Cursors.Hand
        Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Button1.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button1.ForeColor = System.Drawing.SystemColors.InfoText
        Me.Button1.Location = New System.Drawing.Point(8, 272)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(144, 40)
        Me.Button1.TabIndex = 6
        Me.Button1.Text = "Wage"
        '
        'LbResult
        '
        Me.LbResult.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LbResult.ForeColor = System.Drawing.SystemColors.InfoText
        Me.LbResult.Location = New System.Drawing.Point(168, 272)
        Me.LbResult.Name = "LbResult"
        Me.LbResult.Size = New System.Drawing.Size(120, 40)
        Me.LbResult.TabIndex = 7
        Me.LbResult.Text = "Displays Here"
        '
        'Label9
        '
        Me.Label9.Font = New System.Drawing.Font("Times New Roman", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label9.Location = New System.Drawing.Point(8, 328)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(312, 40)
        Me.Label9.TabIndex = 8
        Me.Label9.Text = "Canculate Gross Pay =                                 (Wage -  20% Tax - 7% Natio" & _
        "nal Insurance)"
        '
        'Label5
        '
        Me.Label5.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(8, 96)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(408, 24)
        Me.Label5.TabIndex = 9
        Me.Label5.Text = "Canculate Wage (Wage Per Hour x Hours Worked)"
        '
        'Button2
        '
        Me.Button2.BackColor = System.Drawing.Color.Lime
        Me.Button2.Cursor = System.Windows.Forms.Cursors.Hand
        Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Button2.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button2.ForeColor = System.Drawing.SystemColors.InfoText
        Me.Button2.Location = New System.Drawing.Point(8, 464)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(144, 40)
        Me.Button2.TabIndex = 10
        Me.Button2.Text = "Gross Pay"
        '
        'LbResult2
        '
        Me.LbResult2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LbResult2.ForeColor = System.Drawing.SystemColors.InfoText
        Me.LbResult2.Location = New System.Drawing.Point(160, 464)
        Me.LbResult2.Name = "LbResult2"
        Me.LbResult2.Size = New System.Drawing.Size(128, 40)
        Me.LbResult2.TabIndex = 14
        Me.LbResult2.Text = "Displays Here"
        '
        'LbTax
        '
        Me.LbTax.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LbTax.ForeColor = System.Drawing.Color.Red
        Me.LbTax.Location = New System.Drawing.Point(208, 384)
        Me.LbTax.Name = "LbTax"
        Me.LbTax.Size = New System.Drawing.Size(56, 26)
        Me.LbTax.TabIndex = 16
        Me.LbTax.Text = "20%"
        '
        'LbIns
        '
        Me.LbIns.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.LbIns.ForeColor = System.Drawing.Color.Red
        Me.LbIns.Location = New System.Drawing.Point(208, 416)
        Me.LbIns.Name = "LbIns"
        Me.LbIns.Size = New System.Drawing.Size(56, 26)
        Me.LbIns.TabIndex = 17
        Me.LbIns.Text = "7%"
        '
        'ListBox1
        '
        Me.ListBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ListBox1.ItemHeight = 20
        Me.ListBox1.Items.AddRange(New Object() {"I N F O    B A R", "Hours Worked" & Microsoft.VisualBasic.ChrW(9) & "Pay Rate", "36+ Hours" & Microsoft.VisualBasic.ChrW(9) & "£7.45 ", "44 Hours " & Microsoft.VisualBasic.ChrW(9) & Microsoft.VisualBasic.ChrW(9) & "£10.32", "45+ Hours" & Microsoft.VisualBasic.ChrW(9) & "£15.66 "})
        Me.ListBox1.Location = New System.Drawing.Point(328, 128)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(224, 104)
        Me.ListBox1.TabIndex = 18
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.Label4.Location = New System.Drawing.Point(8, 384)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(192, 24)
        Me.Label4.TabIndex = 19
        Me.Label4.Text = "Tax Deduction"
        '
        'Label6
        '
        Me.Label6.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.Label6.Location = New System.Drawing.Point(8, 424)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(192, 24)
        Me.Label6.TabIndex = 20
        Me.Label6.Text = "Insurance Deduction"
        '
        'Label7
        '
        Me.Label7.Font = New System.Drawing.Font("Times New Roman", 20.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.Location = New System.Drawing.Point(16, 16)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(320, 40)
        Me.Label7.TabIndex = 21
        Me.Label7.Text = "BestWay Pay Calculator"
        Me.Label7.TextAlign = System.Drawing.ContentAlignment.TopCenter
        '
        'Label8
        '
        Me.Label8.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label8.ForeColor = System.Drawing.Color.Red
        Me.Label8.Location = New System.Drawing.Point(336, 24)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(248, 24)
        Me.Label8.TabIndex = 22
        Me.Label8.Text = "Copyrights Fa$ Software Ltd"
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(312, 240)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(264, 304)
        Me.PictureBox1.TabIndex = 23
        Me.PictureBox1.TabStop = False
        '
        'Label10
        '
        Me.Label10.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label10.ForeColor = System.Drawing.Color.Red
        Me.Label10.Location = New System.Drawing.Point(16, 56)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(136, 16)
        Me.Label10.TabIndex = 24
        Me.Label10.Text = "Version 1.0"
        '
        'CrystalReportViewer1
        '
        Me.CrystalReportViewer1.ActiveViewIndex = -1
        Me.CrystalReportViewer1.Location = New System.Drawing.Point(0, 0)
        Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
        Me.CrystalReportViewer1.ReportSource = Nothing
        Me.CrystalReportViewer1.TabIndex = 0
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(16, 528)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(136, 40)
        Me.Button3.TabIndex = 25
        Me.Button3.Text = "Button3"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.ControlLightLight
        Me.ClientSize = New System.Drawing.Size(608, 578)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.LbIns)
        Me.Controls.Add(Me.LbTax)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.LbResult2)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.LbResult)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Cursor = System.Windows.Forms.Cursors.Arrow
        Me.Name = "Form1"
        Me.Text = "BestWay Pay Calculator"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim result As Double = Val(TextBox2.Text) * Val(TextBox3.Text)
        LbResult.Text = String.Format("{0:n2}", result)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim result As Double = Val(TextBox2.Text) * Val(TextBox3.Text)
        LbResult.Text = String.Format("{0:n2}", result)

        Dim result2 As Double = Val(LbResult.Text) - Val(LbTax.Text) - Val(LbIns.Text)
        LbResult2.Text = String.Format("{0:n2}", result2)
    End Sub
End Class
 
Add a button named print to your application, declare a print document in the form class

VB.NET:
Friend WithEvents Pd As System.Drawing.Printing.PrintDocument

In the formload(u will get the form load event if you double click the form in the design view) add this

VB.NET:
Pd = New System.Drawing.Printing.PrintDocument

Add the following print code to your main form class

VB.NET:
Private Sub InitializeFormForPrinting()


PicForm = New PictureBox

End Sub
Public Overloads Sub PrintForm(ByVal TheForm As Form, ByVal ButtonVisibility As Boolean, Optional ByVal Printer As String = "")
If blnFirstTimeThrough Then
InitializeFormForPrinting()
blnFirstTimeThrough = False
End If
If ButtonVisibility = False Then
Call ButtonMagic(TheForm, False)
End If


SendKeys.SendWait("%{PRTSC}")

'get clipboard image and put it in a picturebox
PicForm.Image = DirectCast(System.Windows.Forms.Clipboard.GetDataObject.GetData _
(System.Windows.Forms.DataFormats.Bitmap), Bitmap)
Try
If Printer.Length > 0 Then Pd.PrinterSettings.PrinterName = Printer
Pd.Print()
Catch err As Exception
MessageBox.Show(err.ToString(), "Print Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Call ButtonMagic(TheForm, True)
End Try
End Sub
Public Overloads Sub PrintForm(ByVal TheForm As Form, Optional ByVal Printer As String = "")
If blnFirstTimeThrough Then
InitializeFormForPrinting()
blnFirstTimeThrough = False
End If
Call ButtonMagic(TheForm, True)


SendKeys.SendWait("%{PRTSC}")

'get clipboard image and put it in a picturebox
PicForm.Image = DirectCast(System.Windows.Forms.Clipboard.GetDataObject.GetData _
(System.Windows.Forms.DataFormats.Bitmap), Bitmap)
Try
If Printer.Length > 0 Then Pd.PrinterSettings.PrinterName = Printer
Pd.Print()
Catch err As Exception
MessageBox.Show(err.ToString(), "Print Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
Call ButtonMagic(TheForm, True)
End Try
End Sub
Private Sub ButtonMagic(ByVal TheContainer As Control, ByVal ButtonVisibility As Boolean)
Dim c As Control
'Dim mnu As Men
' Look at each of the controls in the form or in the current container
For Each c In TheContainer.Controls
' If the control is itself a container then call the ButtonMagic
' and give it the new container to iterate
If Not c.Controls Is Nothing Then
ButtonMagic(c, ButtonVisibility)
End If
'If the control is a command button, check the desired visibility
'and change all buttons to that setting
If TypeOf c Is Button Then
If ButtonVisibility = True Then
c.Visible = False
Else
c.Visible = False
End If
End If
Next
End Sub
Private Sub Pd_BeginPrint(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Pd.BeginPrint
Pd.DefaultPageSettings.Landscape = False
Dim sz As SizeF = PicForm.Image.GetBounds(GraphicsUnit.Pixel).Size
Dim pw As Integer = Pd.DefaultPageSettings.Bounds.Width
pw -= Pd.DefaultPageSettings.Margins.Left
pw -= Pd.DefaultPageSettings.Margins.Right
'landscape if image unscaled is wider than marginbounds width
If sz.Width > pw Then Pd.DefaultPageSettings.Landscape = True
End Sub
Private Sub pd_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Pd.PrintPage
'Dim c As Control
Dim thecontrol As Control
Dim mnu As MenuItem
Dim frm As Form1
Dim sz As SizeF = PicForm.Image.GetBounds(GraphicsUnit.Pixel).Size
'scale image if it unscaled doesn't fit marginbounds
If sz.Height > e.MarginBounds.Size.Height Or sz.Width > e.MarginBounds.Size.Width Then
Dim scaleheight As Double = sz.Height / e.MarginBounds.Size.Height
Dim scalewidth As Double = sz.Width / e.MarginBounds.Size.Width
Dim scale As Double = Math.Max(scalewidth, scaleheight)
scalewidth = sz.Width / scale
scaleheight = sz.Height / scale
sz = New SizeF(scalewidth, scaleheight)
Dim scalebounds As New RectangleF(e.MarginBounds.Location, sz)
'draw scaled image
e.Graphics.DrawImage(PicForm.Image, scalebounds)
Else
'draw unscaled image
e.Graphics.DrawImageUnscaled(PicForm.Image, e.MarginBounds)
End If
e.HasMorePages = False 'this is the last page to print
For Each c As Control In Me.Controls
If TypeOf c Is Button Then
c.Visible = True
End If
'If TypeOf mnu Is MenuItem Then
' mnu.Visible = True
'End If
Next
End Sub

Add the following code to your print button event

VB.NET:
PrintDialog1.Document = Pd
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
'System.Threading.Thread.Sleep(10)
PrintForm(Me, PrintDialog1.PrinterSettings.PrinterName)
End If

HTH
--kris
 
Back
Top