Reputation: 69
I have following code in a printing dialog in a windows form.
myPrintDialog = new PrintDialog();
System.Drawing.Bitmap memoryImage = new System.Drawing.Bitmap(pnVTCard.Width, pnVTCard.Height);
pnVTCard.DrawToBitmap(memoryImage, pnVTCard.ClientRectangle);
if (myPrintDialog.ShowDialog() == DialogResult.OK)
{
System.Drawing.Printing.PrinterSettings values;
values = myPrintDialog.PrinterSettings;
myPrintDialog.Document = printDocument1;
printDocument1.PrintController = new StandardPrintController();
printDocument1.Print();//This line shows system.drawing invalid printer exception when i hover over the code.
saveToVC(Convert.ToInt32(cmbVID.SelectedItem.ToString()), cmbElectionName.SelectedItem.ToString());
}
printDocument1.Dispose();
public System.Drawing.Printing.PrintDocument printDocument1 { get; set; }
when I try to handle the exception it shows null reference. Can someone kindly show what to correct. As I don't know much about this can some one explain me what the wrong I'm doing here.? pnVTcard is a panel control
Upvotes: 0
Views: 1312
Reputation: 8466
Make sure you use references which are set to an instance of an object (sounds familiar? :) )
Maybe you are not setting printDocument1 before accessing its properties. Or maybe some other object, like those cmb... SelectedItem.
If you still can't pinpoint the culprit, go ahead and use break points and manually inspect the references.
Upvotes: 1