Disappearing Image
I got the following Code from a book which was devoted to 2005 Express. I put an image in the PictureBox(picPic) and can go on to print it. [In this program I have a PrintPreview so saving the actual print.] However! After printing the image disappears from the Form (And I suspect the actual PictureBox as well!). If I use the event to select a different image, this new one doesn't appear on the Form but it shows on the PrintPreview and prints. Can some kind person please tell me why this is happening. I have obviously tried to work it out, but I am baffled!
Please let me have the solution.
Thanks in advance. AliBong.
Imports
System.DrawingImports
System.Drawing.Drawing2DImports
System.Drawing.ImagingImports
System.IOImports
System.Drawing.TextImports
System.Drawing.PrintingPublic
Class Form1PrivateSub btnGetPic_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnGetPic.Click
If ofdPic.ShowDialog = Windows.Forms.DialogResult.OKThen
picPic.Image = Image.FromFile(ofdPic.FileName)
txtPic.Text = ofdPic.FileName
EndIf
EndSub
PrivateSub btnPrintPic_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnPrintPic.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
'PrintDocument1.Print()
EndSub
PrivateSub PrintDocument1_PrintPage(ByVal senderAsObject,ByVal eAs System.Drawing.Printing.PrintPageEventArgs)Handles PrintDocument1.PrintPage
With PrintDocument1.DefaultPageSettings.PaperSize
If picPic.Width < .WidthThen
picPic.Left = (.Width - picPic.Width) / 2
Else
picPic.Left = 0
EndIf
EndWith
With PrintDocument1.DefaultPageSettings.PaperSize
If picPic.Height < .HeightThen
picPic.Top = (.Height - picPic.Height) / 2
Else
picPic.Top = 0
EndIf
EndWith
Dim rAs Rectangle =New Rectangle(picPic.Left, _
picPic.Top, picPic.Width, picPic.Height)
Console.WriteLine(ofdPic.FileName)
e.Graphics.DrawImage(picPic.Image, r)
EndSub

