Printing Form with labels
Hi,
Can some one pls tell me how to print a form with labels.The code Ive tried is like this:
VB Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
pd1.PrintPage
Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New _
Point(0, 0), Me.Size))
Dim ctl As Control
Static fntHeadingFont As New Font("Arial", 12, FontStyle.Bold)
Try
For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
'Me.InvokePaint(Me, myPaintArgs)
'I need to get the object to print all labels on page in the exact postion
End If
Next
e.HasMorePages = False
Catch ex As Exception
MessageBox.Show("An error occurred while printing", _
ex.ToString())
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub printbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbutton.Click
Try
pd1.Print()
Catch ex As Exception
MessageBox.Show("An error occurred while printing", _
ex.ToString())
End Try
End Sub
Re: Printing Form with labels
I suggest that you forget printing Labels. Print the text that is in the Labels. You have the Size, Location, Text and Font properties of all the Labels so use those to just print text.
Re: Printing Form with labels
or print the entire form as an image with the help provided in my sig
Re: Printing Form with labels
hi,
As with jmcilhinney, can u give me an example. pls cos
Re: Printing Form with labels
The 2003 101 Samples contains a printing example. See my signature for a link if you want to go that way.