Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting a Form/UserControl in C#
    primarykey
    data
    text
    <p><strong>My Program:</strong> Contains a form with few textboxes and one button. 'Default Printer' is set as <em>Adobe PDF</em> on my computer.</p> <p><strong>My Goal:</strong> Want to take a screenshot of a form/usercontrol when the user clicks 'Print' button. The screenshot is then saved on the desktop in .pdf format.</p> <p><strong>My Problem:</strong> I have following two problems with the code:</p> <ol> <li><strong>Size of Screenshot:</strong> The size of the screenshot is too big and it does not fit the size of the page (default page size) when printed/converted to <em>.pdf</em>. Please refer the two images below. I want the entire screenshot to fit inside the page.</li> <li><strong>Asks twice where to convert and save:</strong> When I click on 'Print Form' button, programs asks me 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.</li> </ol> <p>Problem 1: The screenshot captured by the program does not fit the page when printed. <img src="https://i.stack.imgur.com/auGBB.png" alt="Problem 1: The screenshot captured by the program does not fit the page when printed."></p> <p>I want the screenshot image to fit like this on one page of <em>.pdf</em>: <img src="https://i.stack.imgur.com/7FP3j.png" alt="enter image description here"></p> <p><strong>Code:</strong></p> <pre><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); } } </code></pre> <p>Thanks for your help in advance. I am a newbie, learning c# language and your help will be much appreciated. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload