Printing form in C#
How do I scale image of Windows form down so it fits printed page?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
R J192 reputationPosted Aug 19, 2014, 6:40 PM EDT
Usually you can set either to Auto or stretch so that it fits to the window/control .
See other properties in below link.
http://msdn.microsoft.com/en-us/library/system.windows.forms.pictureboxsizemode(v=vs.110).aspx
Louis Klauder3 reputationPosted Aug 20, 2014, 8:16 AM EDT
I forgot that my application already contained a handler and function:
this.PrintDocument_inst.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.k_line_PrintPage);
private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)
which latter includes the following code block in which I was able to alter the value of _scale_f to obtain the result I needed
float _scale_f;
if ( PrintDialog_inst != null )
{
string str_printer_name = PrintDialog_inst.PrinterSettings.PrinterName.ToString ( );
switch( str_printer_name )
{
case "Adobe PDF":
_scale_f = 0.85F;
break;
case "Microsoft XPS Document Writer":
_scale_f = 0.80F; // 0.85F;
break;
default:
_scale_f = 0.94F; // 1.0f; // 0.59F; //
break;
}
}
else // case of print preview
{
_scale_f = 0.59F; // 0.82F;
}
if ( _scale_f != 1.0F ) ppea.Graphics.ScaleTransform ( _scale_f, _scale_f );
ppea.Graphics.DrawImage ( plot_metafile, leftMargin, topMargin );
ppea.HasMorePages = ( --n_pages_still_to_print > 0 ? true : false );