System.Windows.Forms.ThemeWin32Classic.PrintPreviewControlGetPageSize C# (CSharp) Method

PrintPreviewControlGetPageSize() public method

public PrintPreviewControlGetPageSize ( System.Windows.Forms.PrintPreviewControl preview ) : Size
preview System.Windows.Forms.PrintPreviewControl
return System.Drawing.Size
		public override Size PrintPreviewControlGetPageSize (PrintPreviewControl preview)
		{
			int page_width, page_height;
			int padding = PrintPreviewControlPadding;
			PreviewPageInfo[] pis = preview.page_infos;

			if (preview.AutoZoom) {
				int height_available = preview.ClientRectangle.Height - (preview.Rows) * padding - 2 * padding;
				int width_available = preview.ClientRectangle.Width - (preview.Columns - 1) * padding - 2 * padding;

				float image_ratio = (float)pis[0].Image.Width / pis[0].Image.Height;

				/* try to lay things out using the width to determine the size */
				page_width = width_available / preview.Columns;
				page_height = (int)(page_width / image_ratio);

				/* does the height fit? */
				if (page_height * (preview.Rows + 1) > height_available) {
					/* no, lay things out via the height */
					page_height = height_available / (preview.Rows + 1);
					page_width = (int)(page_height * image_ratio);
				}
			}
			else {
				page_width = (int)(pis[0].Image.Width * preview.Zoom);
				page_height = (int)(pis[0].Image.Height * preview.Zoom);
			}

			return new Size (page_width, page_height);
		}
ThemeWin32Classic