I have used the following code to print out a 810 by 788 Windows Form:
private void bunifuFlatButton2_Click(object sender, EventArgs e)
{
bunifuFlatButton2.Hide();
PaperSize ps = new PaperSize("custom", 828, 750);
ps.RawKind = (int)PaperKind.A4;
Graphics graph = CreateGraphics();
bmp = new Bitmap(Size.Width, Size.Height, graph);
graph = Graphics.FromImage(bmp);
printDocument1.DefaultPageSettings.PaperSize = ps;
printPreviewDialog1.ShowDialog();
bunifuFlatButton2.Show();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x = SystemInformation.WorkingArea.X;
int y = SystemInformation.WorkingArea.Y;
int width = 810;
int height = 750;
Rectangle bounds = new Rectangle(x, y, width, height);
Bitmap img = new Bitmap(width, height);
this.DrawToBitmap(img, bounds);
Point p = new Point(-8, -50);
e.Graphics.DrawImage(img, p);
}
The problem is it doesn't cover the whole A4 paper and only part of the paper is covered. Is there a way to make the form cover the whole A4 paper?