My program: Contains a form with several text fields and one button. The default printer is installed as Adobe PDF on my computer.
My goal: Want to take a screenshot of the form / usercontrol when the user clicks the Print button. Then the screenshot is saved on the desktop in .pdf format.
My problem: I have the following two problems with the code:
- Screenshot size: The screenshot size is too large, and it does not match the page size (default page size) when printing / converting to .pdf. See Two Images Below. I want the whole screenshot to fit inside the page.
- Twice asks where to convert and save:. When I click the "Print Form" button, the programs ask me for TWICE where to print / convert and save the file. I want the program to ask me only once, where to print and save the file.
Problem 1: The screenshot taken by the program does not match the page when printing. 
I want the image in the screenshot to match this on one .pdf page: 
Code:
public partial class Form1 : Form { public Form1() { InitializeComponent(); button1.Text = "Print Form"; button1.Click += new EventHandler(button1_Click); printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); this.Controls.Add(button1); } 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); } }
Thanks for your help in advance. I am new to learning the C # language and your help would be much appreciated. :)
source share