internal SystemForm(FORM_INFO_1 form) { this.Name = form.Name; this.IsUserForm = form.Flags == 0; this.PageSize = ((Size)form.Size); this.ImageableArea = (Rect)form.ImageableArea; }
protected override void ProcessRecord() { if (string.IsNullOrWhiteSpace(Name)) { throw new ArgumentNullException(nameof(Name)); } if (Size.IsEmpty) { throw new ArgumentNullException(nameof(Size)); } if (Size.Height < Margin.Top + Margin.Bottom || Size.Width < Margin.Left + Margin.Right) { throw new InvalidOperationException("Margins exceed pagesize"); } Size pageSize = Size; Rect imageableArea = new Rect(Margin.Left, Margin.Top, pageSize.Width - (Margin.Left + Margin.Right), pageSize.Height - (Margin.Top + Margin.Bottom)); switch (Units) { case FormUnits.Inches: pageSize = InchesToMicrons(pageSize); imageableArea = new Rect(InchesToMicrons(imageableArea.TopLeft), InchesToMicrons(imageableArea.BottomRight)); break; case FormUnits.Millimeters: pageSize = MMToMicrons(pageSize); imageableArea = new Rect(MMToMicrons(imageableArea.TopLeft), MMToMicrons(imageableArea.BottomRight)); break; } using (var hServer = OpenPrinter(null)) { var form = new FORM_INFO_1() { Flags = 0, Name = this.Name, Size = (SIZEL)pageSize, ImageableArea = (RECTL)imageableArea }; if (!AddForm(hServer, 1, ref form)) { throw new Win32Exception(); } } }
internal static extern bool AddForm(SafePrinterHandle hPrinter, int level, [In] ref FORM_INFO_1 form);