Experts Exchange connects you with the people and services you need so you can get back to work.
private void button1_Click(object sender, EventArgs e)
//printer selection dialog
PrintDialog PD = new PrintDialog();
DialogResult DR = PD.ShowDialog();
//if printer is selected
if (DR == DialogResult.OK)
PaperSize PrinterPaperSize = PD.PrinterSettings.PaperSizes;
//you might skip this check if names are different on your printer
if (PrinterPaperSize.PaperName != "CR80 Card")
MessageBox.Show("Selected printer doesn't support PVC cards");
printDocument1.PrinterSettings = PD.Printersettings;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
//load background image
Image background = Image.FromFile("c:\\aaa\\image.bmp");
//create graphics object. we use it to draw onto background image
Graphics g = Graphics.FromImage(background);
//draw some strings
Font PrintFont = new Font("Arial",11);
SolidBrush PrintBrush = new SolidBrush(Color.FromArgb(0,54,121));
g.DrawString("ABC123", PrintFont, PrintBrush, 235, 525);
g.DrawString("Name surname", PrintFont, PrintBrush, 780, 525);
//draw some shapes
g.DrawRectangle(Pens.Red, 30, 60, 127, 450);
g.DrawEllipse(Pens.Green, 145, 274, 380, 500);
//when all drawing to the image is done, tell printer to print it
Rectangle PrintRect = new Rectangle(0, 0, printDocument1.PrinterSettings.PaperSizes.Width, printDocument1.PrinterSettings.PaperSizes.Height);
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.