public PrintingWork(LabelModel model, Int32 count, Int32 width, Int32 height) { PrintingLabel = model; Count = count; Width = width; Height = height; Document = new PrintDocument(); Document.PrintPage += new PrintPageEventHandler(PrintHandler); Document.DefaultPageSettings.PaperSize = new PaperSize("Custom Label", Convert.ToInt32(ToInches(width) * 100), Convert.ToInt32(ToInches(height) * 100)); Document.DefaultPageSettings.Margins = new Margins(1, 1, 1, 1); Document.DefaultPageSettings.Color = false; Document.DefaultPageSettings.PrinterResolution = new PrinterResolution { Kind = PrinterResolutionKind.Custom, X = 300, Y = 300 }; }
public static PrintingLayoutBase GetLayout(PrintDocument document, LabelModel label, Int32 width, Int32 height) { switch (LayoutLinesCount(label)) { case PrintingLayoutType.OneLine: return(new OneLineIndexLayout(document, label, width, height)); case PrintingLayoutType.OneLongLine: return(new OneLongLineIndexLayout(document, label, width, height)); case PrintingLayoutType.TwoLines: return(new TwoLineIndexLayout(document, label, width, height)); case PrintingLayoutType.ThreeLines: return(new ThreeLineIndexLayout(document, label, width, height)); default: return(new OneLineIndexLayout(document, label, width, height)); } }
private static PrintingLayoutType LayoutLinesCount(LabelModel label) { var length = label.Customer.Length; if (length > TwoLineIndexLayout.MaxIndexLength) { return(PrintingLayoutType.ThreeLines); } if (length > OneLongLineIndexLayout.MaxIndexLength) { return(PrintingLayoutType.TwoLines); } if (length > OneLineIndexLayout.MaxIndexLength) { return(PrintingLayoutType.OneLongLine); } return(PrintingLayoutType.OneLine); }