public override void Print() { DGVPrinter printer = new DGVPrinter(); printer.Title = "Meriweather Mowing Service"; printer.SubTitle = "Employee Listing"; printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip; printer.PageNumbers = true; printer.PageNumberInHeader = false; printer.PorportionalColumns = true; printer.HeaderCellAlignment = StringAlignment.Near; printer.Footer = "Meriweather Management System"; printer.FooterSpacing = 15; // use saved settings if (null != MMSUtility.myPrinterSettings) printer.printDocument.PrinterSettings = MMSUtility.myPrinterSettings; if (null != MMSUtility.myPageSettings) printer.printDocument.DefaultPageSettings = MMSUtility.myPageSettings; if (DialogResult.OK == printer.DisplayPrintDialog()) // replace DisplayPrintDialog() // with your own print dialog { // save users' settings MMSUtility.myPrinterSettings = printer.PrintSettings; MMSUtility.myPageSettings = printer.PageSettings; // print without displaying the printdialog printer.PrintNoDisplay(employeeDataGridView); } }
internal static void PrintNow(DataGridView p_2, string title, string foter, bool casherprinter) { try { //data grid font DataGridViewCellStyle rd = new DataGridViewCellStyle(p_2.RowsDefaultCellStyle); rd.Font = FontPrint; Font oldfont = p_2.RowsDefaultCellStyle.Font; p_2.RowsDefaultCellStyle = rd; int oldwidth = p_2.Width; DataGridGVeiwPrinter.DGVPrinter Pr = new DGVPrinter(); Pr.Footer = foter + Environment.NewLine + "الليث للمحاسبة"; Pr.CellAlignment = System.Drawing.StringAlignment.Center; Pr.EnableLogging = false; Pr.FooterBorder = new System.Drawing.Pen(System.Drawing.Brushes.Black, 1); Pr.FooterFont = Pr.TitleFont = Globals.FontPrintTitle; Pr.HeaderCellAlignment = System.Drawing.StringAlignment.Center; Pr.ShowTotalPageNumber = false; Pr.PageNumbers = false; Pr.TableAlignment = DGVPrinter.Alignment.Center; Pr.Title = Globals.CompanyName + Environment.NewLine + title + " " + MyDateTime.Now.ToString(); Pr.TitleAlignment = System.Drawing.StringAlignment.Center; if (casherprinter) { Pr.PrinterName = Globals.CasherPrinter; try { p_2.Columns["ArabicUnit"].Visible = false; } catch { } string[] marg = Globals.CasherPrinterMarGin.Split(','); Pr.PrintMargins.Left = int.Parse(marg[0]); Pr.PrintMargins.Right = int.Parse(marg[1]); Pr.PrintMargins.Top = int.Parse(marg[2]); Pr.PrintMargins.Bottom = int.Parse(marg[3]); PrepeareStyleo(p_2, int.Parse(CasherPrinterWidth)); Pr.PrintDataGridView(p_2, false); try { p_2.Columns["ArabicUnit"].Visible = true; } catch { } } else { if (Pr.DisplayPrintDialog() == DialogResult.OK) { PrepeareStyleo(p_2, Pr.PrintSettings.DefaultPageSettings.PaperSize.Width); Pr.PrintPreviewNoDisplay(p_2); } } //data grid font rd = new DataGridViewCellStyle(p_2.RowsDefaultCellStyle); rd.Font = oldfont; p_2.RowsDefaultCellStyle = rd; PrepeareStyleo(p_2, oldwidth); } catch { MessageBox.Show("عذرا يوجد خطأ في في محاولة ضبط حجم الطباعة " + "\n" + "تأكد من تعريف جهاز الطابعة"); } }