I have an issue with printing from a panel (C#, windows form). I created a Print button, I wrote the necessary codes for that and it seems that only one textboxes are able to shown as it is supposed to be. The rest of the controls, such as the richtextboxes are blank, even if I write into them.
Bitmap bitmap;
private void btn_Print_Click(object sender, EventArgs e)
{
Print(this.panel_Doc_Print);
}
public void Print(Panel panel)
{
PrinterSettings set = new PrinterSettings();
panel_Doc_Print = panel;
PrintArea(panel);
print.Document = print_doc;
print_doc.PrintPage += new PrintPageEventHandler(PrintImage);
print.ShowDialog();
}
public void PrintImage(object sender, PrintPageEventArgs e)
{
Rectangle page_area = e.PageBounds;
e.Graphics.DrawImage(bitmap, (page_area.Width / 2) - (this.panel_Doc_Print.Width / 2), this.panel_Doc_Print.Location.Y);
}
public void PrintArea(Panel panel)
{
bitmap = new Bitmap(panel.Width, panel.Height);
panel.DrawToBitmap(bitmap, new Rectangle(0, 0, panel.Width, panel.Height));
}
Before the printing the Windows form looks like this:
Windows form before printing.
Before I click on the print button:
before
After I click on the print button the following happens:
after
What did I do wrong? When I click on the button I want the program to print the whole panel, including all items and control in it. It happens only to the textboxes. As you can see on the 3rd picture the size of the printing image is quite small. I want it to roughly fill out an A4 sheet of paper.
At this point I am too confused to solve this problem alone, therefore I would like to ask for your help.