打印适合A4纸张的Windows窗体

时间:2020-03-06 17:40:00

标签: c# winforms

我使用以下代码来打印810 x 788 Windows窗体:

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);

    }

问题在于它不能覆盖整个A4纸,而仅覆盖部分纸。有没有办法使表格覆盖整个A4纸?

0 个答案:

没有答案
相关问题