none
Printer does not change page orientation. RRS feed

  • Question

  • Hi, I have the code below which works OK, except for the paper orientation.

    The printer refuses to set to Landscape Mode.

    Can you help?

    Regards

    Francesco C.

     private void button2_Click(object sender,EventArgs e)
                {
                try
                    {
                    PrintDialog chart = new PrintDialog();
                    PrintDocument chart2 = new PrintDocument();
                    chart2.DefaultPageSettings.Landscape=true;
                    chart2.DefaultPageSettings.Color=true;
                    chart2.DocumentName="Chart";
                    chart.Document=chart2;
                    chart.AllowSelection=true;
                    chart.AllowSomePages=false;
                    chart.AllowCurrentPage=true;
                    if(chart.ShowDialog()==DialogResult.OK)
                        chart1.Printing.PrintPreview();
                    }
                catch (Exception ex)
                    {
                    MessageBox.Show("Printer is not responding. Please check the printer is online\n NOTE: Sometimes this is due to long delay in response.","Printer Error!",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
                
                }

    And this is the Preview from the printer.

    Thursday, May 21, 2020 5:41 PM

Answers

All replies

  • Question: You set the settings for "chart2", but I can't see where "chart1" is declared. A typo?
    Friday, May 22, 2020 1:16 AM
    Answerer
  • Hi,

    thank you for your replay.

    I cannot answer your question correctly.

    I am new to C#. I have Copied/Modified the code from a search on the net.

    If I change the line you mention to 'chart2....' i get an error. "PrintDocument does not contain a Definition for Printing...."

    The Chart name is'Chart1'.

    Could it be that 'Chart2' is the name of the printing document?

    I am only speculating as I am still learning.

    Regards

    FrancescoC

    Friday, May 22, 2020 6:52 PM
  • My wild guess would be to set "PrintDocument chart2 = chart1.Printing.PrintDocument;" in the second line of try block, instead of creating an empty PrintDocument object.

    Monday, May 25, 2020 1:20 AM
    Answerer
  • Hi Francesco2017,

    Thank you for posting here.

    My idea is the same as cheong00.

    "chart1" should be a Chart

    If you want to print it horizontally, you can get chart1.Printing.PrintDocument and then set its properties.

    In your code, you have created a new PrintDocument (chart2), but it is not connected to chart1, so all the settings you have made for chart2 have no effect on the final result.

    Try this:

         PrintDocument chart2 = chart1.Printing.PrintDocument;

    Or

                    if (chart.ShowDialog() == DialogResult.OK)
                    {
                        chart1.Printing.PrintDocument = chart2;
                        chart1.Printing.PrintPreview();
                    }

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 25, 2020 2:24 AM
  • Hi,

    thank you very much. It works OK.

    It saved me a lot of trouble.

    Monday, May 25, 2020 8:20 AM