Friday 24 April 2015

Panel printing

private void btnPrint_Click(object sender, EventArgs e)
        {           
            System.Drawing.Printing.PrintDocument doc = new PrintDocument();
            doc.PrintPage += this.Doc_PrintPage1;
            PrintDialog dlgSettings = new PrintDialog();
            dlgSettings.Document = doc;
            //if (dlgSettings.ShowDialog() == DialogResult.OK) // hide this line default Printer is select
            {
                doc.Print();
            }
        }
        private void Doc_PrintPage1(object sender, PrintPageEventArgs e)
        {
            float x = e.MarginBounds.Left;
            float y = e.MarginBounds.Top;
            Bitmap bmp = new Bitmap(this.pnlPrint.Width, this.pnlPrint.Height);
            this.pnlPrint.DrawToBitmap(bmp, new Rectangle(0, 0, this.pnlPrint.Width, this.pnlPrint.Height));
            e.Graphics.DrawImage((Image)bmp, 0, 0);
        }