Question

Creating a print option with a screenshot of the form as i needed the whole form for sure. Which Leads to the additional printing dialog box to the printout.

Here is the code,

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e){
  var scr = Screen.FromPoint(this.Location);
        using (var bmp = new Bitmap(scr.WorkingArea.Width, scr.WorkingArea.Height))
        {
            using (var gr = Graphics.FromImage(bmp))
            {
                gr.CopyFromScreen(new Point(scr.WorkingArea.Left, scr.WorkingArea.Top), Point.Empty, bmp.Size);
            }
            // Determine scaling
            float scale = 1.0f;
            scale = Math.Min(scale, (float)e.MarginBounds.Width / bmp.Width);
            scale = Math.Min(scale, (float)e.MarginBounds.Height / bmp.Height);
            // Set scaling and offset
            e.Graphics.TranslateTransform(e.MarginBounds.Left + (e.MarginBounds.Width - bmp.Width * scale) / 2,
                                          e.MarginBounds.Top + (e.MarginBounds.Height - bmp.Height * scale) / 2);
            e.Graphics.ScaleTransform(scale, scale);
            // And draw
            e.Graphics.DrawImage(bmp, 0, 0);

}

Which displays the dialogbox as shown below, Problem Area

Please Help me in this issue... Thanks in advance...

Was it helpful?

Solution

Add printDocument1.PrintController = new StandardPrintController() before you call printDocument1.Print() By default I believe it uses PrintControllerWithStatusDialog.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top