golocorbin

golocorbin

  • NA
  • 44
  • 101.4k

print - preview Landscape or Portrait

Oct 6 2008 6:32 AM

            where I make mistake ?

  using - PrintDocument---Print() or  PrintPreviewControl

            -PrintPreviewControl ---Show()

            -PrinterSeting

         -----------------------------------

     PageSettings

           PrinterSettings

           PageSetupDialog – ShowDialog() 

            and few other combination  :

 

           I can’t  get   print or preview like Landscape or Portrait programmaticly,

           evry time I get like is my setup in windows setup, so if it is Portrait and

            I wont Landscape, I get Portrait, regardless my programmaticly setup, regardless print or   display     

            and vice versa

           Using  PageSetupDialog  I make change on dialog , but when  after that  I see

           my  real printer setup ,he  stay without change.

           So  evry time I  have  Print or Preview like is windows printer setup, not my.

            Can  .net  printer types reach  real printer seting  (setting from Windows)

           and  change them real? 

             FROM INTERNET AND MY MIX                               

public Form1()

        {

            InitializeComponent();

        }

        internal PrintPreviewControl PrintPreviewControl1;

        private System.Drawing.Printing.PrintDocument docToPrint =

        new System.Drawing.Printing.PrintDocument();

        PrinterSettings pera = new PrinterSettings();

           /*

                        OR

       

        public void ShowPageSettings()

        {

            PrinterSettings mika = new PrinterSettings();

            PageSetupDialog setup = new PageSetupDialog();

            PageSettings settings = docToPrint.DefaultPageSettings; //

            setup.PageSettings = settings;

            mika = setup.PrinterSettings;

 

            // display the dialog and,

            if (setup.ShowDialog() == DialogResult.OK)

                setup.PageSettings = docToPrint.DefaultPageSettings;

               docToPrint.DefaultPageSettings = setup.PageSettings;

              NO EFFEKT ON REAL PRINTER SETUP – PAGE ORIENTATION  

        }  

    */

        private void  docToPrint_PrintPage(object sender, PrintPageEventArgs e)

        {

               //   REAL PRINTER SETUP IS PORTRAIT

 

            string text = "In docToPrint_PrintPage method.";

            System.Drawing.Font printFont =

                new Font("Arial", 35, FontStyle.Regular);

          

            this.pera.PrinterName =". . ." ;

            if (this.pera.IsValid) --------------TRUE

            {

           this.pera.DefaultPageSettings.Landscape = true; ---NO EFFEKT

            this.docToPrint.DefaultPageSettings.Landscape = true;-- NO

                                                                 EFFEKT

                if (pera.DefaultPageSettings.Landscape)--TRUE

                    e.Graphics.DrawString(text, printFont, 

                        Brushes.Black, 10, 10);

         //        REAL PRINTER SETUP NOT CHANGED –IS PORTRAIT !

         //        PAPER LAYOUT(PRINT OR DISPLAY)IS LIKE REAL PRINTER

         //        SETUP—IS PORTRAIT !                     

 

            }

       

        }

 

        private void InitializePrintPreviewControl()

        {

           

            this.PrintPreviewControl1 = new PrintPreviewControl();

           

            // Set location, name, and dock style for 

              PrintPreviewControl1.

            this.PrintPreviewControl1.Location = new Point(88, 80);

            this.PrintPreviewControl1.Name = "PrintPreviewControl1";

             . . .

            

            this.Controls.Add(this.PrintPreviewControl1);

 

            // Associate the event-handling method with the

            // document's PrintPage event.

            this.docToPrint.PrintPage +=

                new System.Drawing.Printing.PrintPageEventHandler(

               docToPrint_PrintPage);

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

          

           InitializePrintPreviewControl();

           // or  

          // this.ShowPageSettings();

        }