skip to Main Content

I’m trying to print a report in Visual Studio Windows Form.
The report should have a logo and intestation for each page and the page orientation should be landscape.
The body of report is displayed in a RichTextBox.

I tried but I don’t understand how to modify the page orientation and page break.

Can you help me?

This is the code:

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 is the button that I use to print the report.

If I print the report I see:

enter image description here

But I’d like a different page orientation and I don’t know if at the end of the pages at pages 2 the logo and intestation repeted.

2

Answers


  1. Chosen as BEST ANSWER

    Thank's work fine. Can you help me olso for page print preview? This view continue with old orientation.

    And another question, it is possible repeat the following two lines:

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

    for all the pages printed?


  2. Add this line of code to your program and you can see changes of the print page orientation when you execute it.

    printDocument1.DefaultPageSettings. Landscape = true;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search