當前位置: 首頁>>代碼示例>>C#>>正文


C# SizeF.DivideBy方法代碼示例

本文整理匯總了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]);
        }
開發者ID:saveenr,項目名稱:saveenr,代碼行數:71,代碼來源:SSRSPrintPreview.cs


注:本文中的System.Drawing.SizeF.DivideBy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。