Quantcast
Viewing all articles
Browse latest Browse all 12583

Printing Form - prints blank page

Using the code example from MSDN on how to print a windows form, I have the altered mine to bring up the printer options first and then print, but I keep receiving a blank page.

private PrintDocument printDoc1 = new PrintDocument();

void printDoc1_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }

private Bitmap memoryImage;

        private void CaptureScreen()
        {
            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);
        }

private void printButton_Click(object sender, EventArgs e)
        {           
            CaptureScreen();
        
            printDialog1.AllowSomePages = true;
         
            printDialog1.ShowHelp = true;

            printDialog1.Document = printDoc1;
           
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                printDoc1.Print();
            }
        }        


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>