panel is control it self
so, use this command
PrintDialog myPrintDialog = new PrintDialog();
System.Drawing.Bitmap memoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(memoryImage, panel1.ClientRectangle);
if (myPrintDialog.ShowDialog() == DialogResult.OK)
{
System.Drawing.Printing.PrinterSettings values;
values = myPrintDialog.PrinterSettings;
myPrintDialog.Document = printDocument1;
printDocument1.PrintController = new StandardPrintController();
printDocument1.Print();
}
printDocument1.Dispose();
or
scale image if it's not fit into page
private void panel1_Click(object sender, EventArgs e)
{
PrintDialog myPrintDialog = new PrintDialog();
memoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
memoryImage.SetResolution(150, 150);
panel1.DrawToBitmap(memoryImage, panel1.ClientRectangle);
memoryImage.Save("E:/a.bmp");
if (myPrintDialog.ShowDialog() == DialogResult.OK)
{
System.Drawing.Printing.PrinterSettings values;
values = myPrintDialog.PrinterSettings;
myPrintDialog.PrinterSettings.DefaultPageSettings.Landscape = true;
printDocument1.DefaultPageSettings = myPrintDialog.PrinterSettings.DefaultPageSettings;
myPrintDialog.Document = printDocument1;
printDocument1.PrintController = new StandardPrintController();
printDocument1.Print();
}
printDocument1.Dispose();
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
SizeF sz = new SizeF(e.PageBounds.Width - e.MarginBounds.Width, e.PageBounds.Height - e.MarginBounds.Height);
PointF p = new PointF((sz.Width) / 70, (sz.Height) / 70);
e.Graphics.DrawImage(memoryImage, p);
}
Note : I have tried to print in Papersize is A5
Happy Coding!
:)