Newbie trying to print

ICW

Active member
Joined
Mar 27, 2006
Messages
25
Programming Experience
Beginner
Hi, I have 3 images on my form and I have created 3 buttons in order to print the 3 images.

The images are called;
picimage, picimage2, picimage3
and the buttons are
btnsmallPrint1, btnsmallPrint2, btnsmallPrint3

i.e. When i click on "btnsmallPrint1" it prints off picimage1 along with a logo and some other info (like filename etc)

I do seem to be most of the way there, as I can print all three images successfully.
The problem is that printing the first one is fine, then the second one seems to still have the filename from the first one with the filename of the second one typed over the top. The when I do the third one it still has the first two filenames and is overwritten with the third.

Basically it looks messy and i can't read the filenames.

you'll see I have tried to 'dispose' the PrintDocument after each one but it doesn't seem to help

I am a newbie so please explain any suggestions in terms that a newbie can understand.

Much appreciated, thanks

code below.

Also I am not sure which type of tags I am supposed to be using to show the code..thanks
PHP:
Private Sub btnsmallPrint1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsmallPrint1.Click
Try
If PrintDialog1.ShowDialog = DialogResult.OK Then
AddHandler PrintDocument1.PrintPage, AddressOf Me.pd_PrintPage1
PrintDocument1.Print()
PrintDocument1.Dispose()
End If
Catch ex As Exception
MessageBox.Show("Printing Error")
End Try
End Sub
Private Sub pd_PrintPage1(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
 
 
Dim rect As RectangleF
rect = ev.Graphics.VisibleClipBounds()
rect.Height = rect.Height / 3
rect.Width = rect.Width / 2
Dim bottomRect As New RectangleF(rect.Left, rect.Bottom, rect.Width, rect.Height)
Dim font As Font = New Font("Arial", 8, FontStyle.Regular, GraphicsUnit.Point)
Dim intfontheight As Integer = font.GetHeight(ev.Graphics)
Dim intCurrentY As Integer = bottomRect.Top
ev.Graphics.DrawImage(PicImage.Image, rect)
ev.Graphics.DrawImage(piclogo.Image, bottomRect.Left, bottomRect.Top + intfontheight * 5)
ev.Graphics.DrawString(lblfilename1.Text, font, Brushes.Black, bottomRect)
ev.Graphics.DrawString(lblScanDate1.Text, font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight)
ev.Graphics.DrawString(lblUniqueID.Text, font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight * 2)
ev.Graphics.DrawString("Print date: " & String.Format(Date.Now), font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight * 3)
ev.HasMorePages = False
 
End Sub
 
Private Sub btnsmallPrint2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsmallPrint2.Click
Try
If PrintDialog1.ShowDialog = DialogResult.OK Then
AddHandler PrintDocument1.PrintPage, AddressOf Me.pd_PrintPage2
PrintDocument1.Print()
PrintDocument1.Dispose()
End If
Catch ex As Exception
MessageBox.Show("Printing Error")
End Try
End Sub
Private Sub pd_PrintPage2(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
 
 
Dim rect As RectangleF
rect = ev.Graphics.VisibleClipBounds()
rect.Height = rect.Height / 3
rect.Width = rect.Width / 2
Dim bottomRect As New RectangleF(rect.Left, rect.Bottom, rect.Width, rect.Height)
Dim font As Font = New Font("Arial", 8, FontStyle.Regular, GraphicsUnit.Point)
Dim intfontheight As Integer = font.GetHeight(ev.Graphics)
Dim intCurrentY As Integer = bottomRect.Top
ev.Graphics.DrawImage(PicImage2.Image, rect)
ev.Graphics.DrawImage(piclogo.Image, bottomRect.Left, bottomRect.Top + intfontheight * 5)
ev.Graphics.DrawString(lblfilename2.Text, font, Brushes.Black, bottomRect)
ev.Graphics.DrawString(lblScanDate2.Text, font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight)
ev.Graphics.DrawString(lblUniqueID.Text, font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight * 2)
ev.Graphics.DrawString("Print date: " & String.Format(Date.Now), font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight * 3)
ev.HasMorePages = False
 
End Sub
Private Sub btnsmallPrint3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsmallPrint3.Click
Try
If PrintDialog1.ShowDialog = DialogResult.OK Then
AddHandler PrintDocument1.PrintPage, AddressOf Me.pd_PrintPage3
PrintDocument1.Print()
PrintDocument1.Dispose()
End If
Catch ex As Exception
MessageBox.Show("Printing Error")
End Try
End Sub
Private Sub pd_PrintPage3(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)
 
 
Dim rect As RectangleF
rect = ev.Graphics.VisibleClipBounds()
rect.Height = rect.Height / 3
rect.Width = rect.Width / 2
Dim bottomRect As New RectangleF(rect.Left, rect.Bottom, rect.Width, rect.Height)
Dim font As Font = New Font("Arial", 8, FontStyle.Regular, GraphicsUnit.Point)
Dim intfontheight As Integer = font.GetHeight(ev.Graphics)
Dim intCurrentY As Integer = bottomRect.Top
ev.Graphics.DrawImage(PicImage3.Image, rect)
ev.Graphics.DrawImage(piclogo.Image, bottomRect.Left, bottomRect.Top + intfontheight * 5)
ev.Graphics.DrawString(lblfilename3.Text, font, Brushes.Black, bottomRect)
ev.Graphics.DrawString(lblScanDate3.Text, font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight)
ev.Graphics.DrawString(lblUniqueID.Text, font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight * 2)
ev.Graphics.DrawString("Print date: " & String.Format(Date.Now), font, Brushes.Black, bottomRect.Left, intCurrentY + intfontheight * 3)
ev.HasMorePages = False
 
End Sub
 
Back
Top