private void navPrint_Click(object sender, EventArgs e) { PrintPreviewDialog curPreviewDialog = new PrintPreviewDialog(); PrintDialog curPrintDialog = new PrintDialog(); bool CenterOnPage = true; bool WithTitle = true; bool WithPaging = true; Font fontPrintTitle = new Font("Arial Narrow", 14, FontStyle.Bold); Font fontPrintFooter = new Font("Times New Roman", 10); try { curPrintDialog.AllowCurrentPage = true; curPrintDialog.AllowPrintToFile = false; curPrintDialog.AllowSelection = true; curPrintDialog.AllowSomePages = true; curPrintDialog.PrintToFile = false; curPrintDialog.ShowHelp = false; curPrintDialog.ShowNetwork = true; curPrintDialog.UseEXDialog = true; curPrintDialog.PrinterSettings.DefaultPageSettings.Landscape = true; if (curPrintDialog.ShowDialog() == DialogResult.OK) { String printTitle = Properties.Settings.Default.Mdi_Title + "\n Sanction " + mySanctionNum + " held on " + myTourRow["EventDates"].ToString() + "\n" + this.Text; myPrintDoc = new PrintDocument(); myPrintDoc.DocumentName = this.Text; myPrintDoc.DefaultPageSettings.Margins = new Margins(25, 25, 25, 25); myPrintDoc.DefaultPageSettings.Landscape = true; myPrintDataGrid = new DataGridViewPrinter(scoreSummaryDataGridView, myPrintDoc, CenterOnPage, WithTitle, printTitle, fontPrintTitle, Color.DarkBlue, WithPaging); myPrintDataGrid.SubtitleList(); StringRowPrinter mySubtitle; StringFormat SubtitleStringFormat = new StringFormat(); SubtitleStringFormat.Trimming = StringTrimming.Word; SubtitleStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; SubtitleStringFormat.Alignment = StringAlignment.Center; if (plcmtDivButton.Checked) { mySubtitle = new StringRowPrinter(TrickLabel.Text, 451, 0, 215, TrickLabel.Size.Height, TrickLabel.ForeColor, TrickLabel.BackColor, TrickLabel.Font, SubtitleStringFormat); myPrintDataGrid.SubtitleRow = mySubtitle; } else { mySubtitle = new StringRowPrinter(TrickLabel.Text, 486, 0, 215, TrickLabel.Size.Height, TrickLabel.ForeColor, TrickLabel.BackColor, TrickLabel.Font, SubtitleStringFormat); myPrintDataGrid.SubtitleRow = mySubtitle; } myPrintDoc.PrinterSettings = curPrintDialog.PrinterSettings; myPrintDoc.DefaultPageSettings = curPrintDialog.PrinterSettings.DefaultPageSettings; myPrintDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); curPreviewDialog.Document = myPrintDoc; curPreviewDialog.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Exception encountered during print request" + "\n\nException: " + ex.Message); } }
private void navPrint_Click(object sender, EventArgs e) { PrintPreviewDialog curPreviewDialog = new PrintPreviewDialog(); PrintDialog curPrintDialog = new PrintDialog(); Font saveShowDefaultCellStyle = scoreSummaryDataGridView.DefaultCellStyle.Font; scoreSummaryDataGridView.DefaultCellStyle.Font = new Font("Tahoma", 10, FontStyle.Regular); bool CenterOnPage = true; bool WithTitle = true; bool WithPaging = true; Font fontPrintTitle = new Font("Arial Narrow", 14, FontStyle.Bold); Font fontPrintFooter = new Font("Times New Roman", 10); curPrintDialog.AllowCurrentPage = true; curPrintDialog.AllowPrintToFile = false; curPrintDialog.AllowSelection = true; curPrintDialog.AllowSomePages = true; curPrintDialog.PrintToFile = false; curPrintDialog.ShowHelp = false; curPrintDialog.ShowNetwork = false; curPrintDialog.UseEXDialog = true; curPrintDialog.PrinterSettings.DefaultPageSettings.Landscape = true; if (curPrintDialog.ShowDialog() == DialogResult.OK) { String printTitle = Properties.Settings.Default.Mdi_Title + "\n Sanction " + mySanctionNum + " held on " + myTourRow["EventDates"].ToString() + "\n" + this.Text; myPrintDoc = new PrintDocument(); myPrintDoc.DocumentName = this.Text; myPrintDoc.DefaultPageSettings.Margins = new Margins(25, 25, 25, 25); myPrintDoc.DefaultPageSettings.Landscape = true; myPrintDataGrid = new DataGridViewPrinter(scoreSummaryDataGridView, myPrintDoc, CenterOnPage, WithTitle, printTitle, fontPrintTitle, Color.DarkBlue, WithPaging); myPrintDataGrid.SubtitleList(); StringRowPrinter mySubtitle; StringFormat SubtitleStringFormat = new StringFormat(); SubtitleStringFormat.Trimming = StringTrimming.Word; SubtitleStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip; SubtitleStringFormat.Alignment = StringAlignment.Center; int curLabelLocSlalom = 0, curLabelLocTrick = 0, curLabelLocJump = 0, curLabelLocOverall = 0; if (myTourRules.ToLower().Equals("ncwsa")) { curLabelLocSlalom = 295; curLabelLocTrick = 572; curLabelLocJump = 737; curLabelLocOverall = 887; } else { if (EventGroup.Visible) { curLabelLocSlalom = 244; curLabelLocTrick = 550; curLabelLocJump = 729; curLabelLocOverall = 897; } else { curLabelLocSlalom = 204; curLabelLocTrick = 517; curLabelLocJump = 697; curLabelLocOverall = 862; } } mySubtitle = new StringRowPrinter(SlalomLabel.Text, curLabelLocSlalom, 0, Convert.ToInt32(SlalomLabel.Width * .8), SlalomLabel.Size.Height, SlalomLabel.ForeColor, SlalomLabel.BackColor, SlalomLabel.Font, SubtitleStringFormat); myPrintDataGrid.SubtitleRow = mySubtitle; mySubtitle = new StringRowPrinter(TrickLabel.Text, curLabelLocTrick, 0, Convert.ToInt32(TrickLabel.Width * .65), TrickLabel.Size.Height, TrickLabel.ForeColor, TrickLabel.BackColor, TrickLabel.Font, SubtitleStringFormat); myPrintDataGrid.SubtitleRow = mySubtitle; mySubtitle = new StringRowPrinter(JumpLabel.Text, curLabelLocJump, 0, Convert.ToInt32(JumpLabel.Width * .65), JumpLabel.Size.Height, JumpLabel.ForeColor, JumpLabel.BackColor, JumpLabel.Font, SubtitleStringFormat); myPrintDataGrid.SubtitleRow = mySubtitle; mySubtitle = new StringRowPrinter(OverallLabel.Text, curLabelLocOverall, 0, OverallLabel.Size.Width, OverallLabel.Size.Height, OverallLabel.ForeColor, OverallLabel.BackColor, OverallLabel.Font, SubtitleStringFormat); myPrintDataGrid.SubtitleRow = mySubtitle; myPrintDoc.PrinterSettings = curPrintDialog.PrinterSettings; myPrintDoc.DefaultPageSettings = curPrintDialog.PrinterSettings.DefaultPageSettings; myPrintDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); curPreviewDialog.Document = myPrintDoc; curPreviewDialog.ShowDialog(); } scoreSummaryDataGridView.DefaultCellStyle.Font = saveShowDefaultCellStyle; }