Getting blank print document on button click using C# Windows application

Viewed 160

I'm trying to print panel contents in C# windows application on button click but, I'm getting blank document have attached some screenshots and code.

enter image description here

enter image description here

My Code:

   private void BtnPrint_Click(object sender, EventArgs e)
    {
        Bitmap bitmap;
        //Add a Panel control.
        Panel panel = new Panel();
        this.Controls.Add(panel);


        Graphics grp = panel.CreateGraphics();
        Size formSize = this.ClientSize;
        bitmap = new Bitmap(formSize.Width, formSize.Height, grp);
        grp = Graphics.FromImage(bitmap);


        Point panelLocation = PointToScreen(panel.Location);
        grp.CopyFromScreen(panelLocation.X, panelLocation.Y, 0, 0, formSize);

        //Show the Print Preview Dialog.
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.PrintPreviewControl.Zoom = 1;
        printPreviewDialog1.ShowDialog();
    }
0 Answers
Related