本文整理汇总了C#中System.Drawing.SizeF.DivideBy方法的典型用法代码示例。如果您正苦于以下问题:C# SizeF.DivideBy方法的具体用法?C# SizeF.DivideBy怎么用?C# SizeF.DivideBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.SizeF
的用法示例。
在下文中一共展示了SizeF.DivideBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: send_metafile_to_printer
private void send_metafile_to_printer(Metafile metafile, PrintPageEventArgs e)
{
// constants
const float unit_factor = 100.0f;
// prefs
var desired_printing_dpi = new System.Drawing.SizeF(300.0f, 300.0f);
// Retrieve metadfile information
var metafile_header = metafile.GetMetafileHeader();
var metafile_dpi = new System.Drawing.SizeF(metafile_header.DpiX, metafile_header.DpiY);
// Based on the orientation command, adjust the printer orientation
var orient_command = SSRSCommon.PageOrientationCommand.UseDefaultPrinterSetting;
if (orient_command == SSRSCommon.PageOrientationCommand.ForceLandscape)
{
e.PageSettings.Landscape = true;
}
else if (orient_command == SSRSCommon.PageOrientationCommand.ForcePortrait)
{
e.PageSettings.Landscape = false;
}
else if (orient_command == SSRSCommon.PageOrientationCommand.UseDefaultPrinterSetting)
{
// do nothing
}
else if (orient_command == SSRSCommon.PageOrientationCommand.UseReportDesign)
{
bool design_landscape = metafile.Width > metafile.Height;
e.PageSettings.Landscape = design_landscape;
}
// Retrieve information about the printer
var papersize = new SD.SizeF(e.PageSettings.PaperSize.Width, e.PageSettings.PaperSize.Height);
//var printable_size = new SD.SizeF(e.PageSettings.PrintableArea.Width, e.PageSettings.PrintableArea.Height);
// ------------------------------------------------------------------
// find the metafile size in printer units
var dpi_factor = metafile_dpi.DivideBy(desired_printing_dpi);
e.Graphics.ScaleTransform(dpi_factor.Width, dpi_factor.Height, System.Drawing.Drawing2D.MatrixOrder.Prepend);
var metafile_size_normalized = metafile.Size.ToSizeF().DivideBy(desired_printing_dpi).MultiplyBy(unit_factor);
var metafile_size_oriented = e.PageSettings.Landscape ? metafile_size_normalized.FlipSides() : metafile_size_normalized;
// ----------------------------------------------------
// Calculate the scaling factor to use on the metafile - do we need to shrink it down to fit the page or not.
float scale_to_fit_factor = 1.0f; // 1.0 = don't scale the metafile at all
if (!metafile_size_normalized.FitsInside(papersize))
{
scale_to_fit_factor = papersize.DivideBy(metafile_size_oriented).GetSmallestSide();
}
// we now have all the information we need to scale
e.Graphics.ScaleTransform(scale_to_fit_factor, scale_to_fit_factor, System.Drawing.Drawing2D.MatrixOrder.Append);
// shift the metafile by hard margin size to aling to the top left side of the paper
int hm_offset_x = (int) e.PageSettings.HardMarginX*-1;
int hm_offset_y = (int) e.PageSettings.HardMarginY * -1;
var hm_offset = new SD.Point(hm_offset_x, hm_offset_y);
var points = new[] { hm_offset };
var matrix = e.Graphics.Transform;
matrix.Invert();
matrix.TransformPoints(points);
// --------------------------------------------------------------------
// Draw the image
e.Graphics.DrawImageUnscaled(metafile, points[0]);
}