Problems with print out a Win Form

33 Views Asked by At

I have a child WinForms Form that I want to be printed out. In my project I've included components prnDocument, prnDialog and prnPreview. I have copied an example from Microsoft site.

        private void btnPrint_Click(object sender, EventArgs e)
        {
            DialogResult dlgresult;
            //prnDocument.PrintPage += new PrintPageEventHandler(prnDocument_PrintPage);
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            _memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(_memoryImage);
            memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
            //prnDocument.PrinterSettings.DefaultPageSettings.Landscape = true;
            dlgresult = prnDialog.ShowDialog();
            prnDocument.Print();
        }
        private void prnDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //e.Graphics.DrawImage(_bmp, 0, 0);
            //e.PageSettings.Landscape= true;
            e.Graphics.DrawImage(_memoryImage, 0, 0);
        }

And it works regarding that it sends something to the printer. But not exactly what it suposed to be. 1.) I want to set the printer temporarily to Landscape. Calling PrinterDialog and changeing there has no effect on printout, nor does changeing DefaultPageSettings.Landscape = true; 2.) The top-left position is outside of my form. 3.) The screencopy pixels are more than the printer pixels for one page. Is there an easy way to scale the screencopy area to printer full page? My printer is a HP Laserjet. Thanks for help.

0

There are 0 best solutions below