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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Louis KlauderPosted Aug 20, 2014, 12:16 PM
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 );
R JPosted Aug 19, 2014, 10:40 PM
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