Hi,

Can some one pls tell me how to print a form with labels.The code Ive tried is like this:


VB Code:
  1. Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
  2.            ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
  3.            pd1.PrintPage
  4.         Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New _
  5.            Point(0, 0), Me.Size))
  6.         Dim ctl As Control
  7.         Static fntHeadingFont As New Font("Arial", 12, FontStyle.Bold)
  8.  
  9.         Try
  10.             For Each ctl In Me.Controls
  11.                 If TypeOf ctl Is Label Then
  12.                     'Me.InvokePaint(Me, myPaintArgs)
  13.                     'I need to get the object to print all labels on page in the exact postion
  14.                 End If
  15.             Next
  16.  
  17.             e.HasMorePages = False
  18.         Catch ex As Exception
  19.             MessageBox.Show("An error occurred while printing", _
  20.                 ex.ToString())
  21.         End Try
  22.  
  23.     End Sub
  24.  
  25.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  26.         PrintPreviewDialog1.ShowDialog()
  27.        
  28.    End Sub
  29.  
  30.  
  31.     Private Sub printbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbutton.Click
  32.         Try
  33.             pd1.Print()
  34.         Catch ex As Exception
  35.             MessageBox.Show("An error occurred while printing", _
  36.                 ex.ToString())
  37.         End Try
  38.     End Sub