打印报告页

问题描述 投票:0回答:1

我正在尝试在 Visual Studio Windows 窗体中打印报告。 报告的每一页都应有徽标和注释,并且页面方向应为横向。 报告正文显示在 RichTextBox 中。

我尝试过,但不明白如何修改页面方向和分页符。

你能帮我吗?

这是代码:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    string IMAGE = "";
    sqlite.Open();  //Initiate connection to the db
    string stm = "SELECT VALORE FROM IMPOSTAZIONI WHERE IMPOSTAZIONE = 'LOGO';";
    using var cmd = new SQLiteCommand(stm, sqlite);
    using SQLiteDataReader rdr = cmd.ExecuteReader();
    while (rdr.Read())
    {
        IMAGE = (string)rdr["VALORE"];
    }
    sqlite.Close();

    Image bgFront = Image.FromFile(@"Immagini\" + IMAGE);

    e.Graphics.DrawImage(bgFront, 0, 0, 100, 100);
    e.Graphics.DrawString("Report Movimenti in Uscita non Pagati", new Font("Courier New", 18, FontStyle.Bold), Brushes.Black, new PointF(160, 40));
    e.Graphics.DrawString(richTextBox1.Text, new Font("Courier New", 14, FontStyle.Bold), Brushes.Black, new PointF(0, 150));
}

private void button1_Click(object sender, EventArgs e)
{
    if (printPreviewDialog1.ShowDialog() == DialogResult.OK)
    {
        printDocument1.Print();
    }
}

Buttoin1 是我用来打印报告的按钮。

如果我打印报告,我会看到:

enter image description here

但是我想要不同的页面方向,并且我不知道在第 2 页的页面末尾是否会重复徽标和注释。

c# visual-studio winforms printing
1个回答
0
投票

将这行代码添加到您的程序中,执行时您可以看到打印页面方向的变化。

printDocument1.DefaultPageSettings. Landscape = true;
© www.soinside.com 2019 - 2024. All rights reserved.