2

I am trying to print windows form with all controls on it as captured screen, but it prints a blank page. Where I am wrong? Here is the code i use:

    private void OutputLaundry_Load(object sender, EventArgs e)
    {
        Out ou = new Out();
        ou.Lst = Main.laundryOutList;
        ou.ClientName = Main.clientOutName;
        ou.Employee = Login.user.Name;
        label2.Text = DateTime.Today.ToString("dd.MM.yyyy");
        label3.Text = ou.ClientName;
        DBC.outputLaundry(dgvOut, ou.Lst);
        label4.Text = ou.Employee;

    }

    private void button1_Click(object sender, EventArgs e)
    {
        CaptureScreen();
        printDocument1.Print();

    }

    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 printDocument1_PrintPage(System.Object sender,
           System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
    }
M.Mihaylov
  • 43
  • 1
  • 8
  • Crystal ball say that your form class sets the Opacity or TransparencyKey property. Which turns the window into a "layered" window, this CopyFromScreen() overload doesn't copy them. You need the overload that takes the CopyPixelOperation argument, but it has an age-old bug. Workaround [is here](http://stackoverflow.com/a/3072580/17034). – Hans Passant Nov 10 '16 at 12:46

0 Answers0