private static int TotalWidth; // Summation of Columns widths #endregion Fields #region Methods public static void Print_DataGrid(C1.Win.C1FlexGrid.C1FlexGrid dgF, String title) { PrintTitle = title; PrintPreviewDialog ppvw; try { dg = dgF; PrintFont = dg.Font; PrintFontColor = dg.ForeColor; //khoaht added foreach (Column c in dg.Cols) if (c.Visible) AvailableColumns.Add(c.Caption); // Show PrintOption Form PrintOptions dlg = new PrintOptions(PrintTitle, AvailableColumns); //if (dlg.ShowDialog() != DialogResult.OK) return; PrintTitle = dlg.PrintTitle; PrintAllRows = dlg.PrintAllRows; SelectedColumns = dlg.GetSelectedColumns(); if (dlg.PrintFont != null) PrintFont = dlg.PrintFont; if (dlg.PrintFontColor.Name != "" & dlg.PrintFontColor.Name != "0") PrintFontColor = dlg.PrintFontColor; RowsPerPage = 0; ppvw = new PrintPreviewDialog(); ppvw.Document = printDoc; // Show Print Preview Page printDoc.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDoc_BeginPrint); printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); if (ppvw.ShowDialog() != DialogResult.OK) { printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(printDoc_BeginPrint); printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); return; } // Print the Documnet printDoc.Print(); printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(printDoc_BeginPrint); printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); } catch (Exception ex) { MsgBoxVN.ShowError(ex.Message, Dic.STRING_TITLE_ERROR); } finally { } }
public static void Print_DataGrid(DataGridView dg1,String title) { PrintTitle = title; PrintPreviewDialog ppvw; try { // Save DataGrid attributes dg = dg1; PrintFont = dg.Font; PrintFontColor = dg.ForeColor; // Get all Coulmns Names in the DataGrid AvailableColumns.Clear(); //foreach (DataGridColumnStyle c in dg.TableStyles[0].GridColumnStyles) // AvailableColumns.Add(c.HeaderText); //khoaht added foreach (DataGridViewColumn c in dg.Columns) if(c.Visible) AvailableColumns.Add(c.HeaderText); // KhoaHT disable print option // Show PrintOption Form PrintOptions dlg = new PrintOptions(PrintTitle, AvailableColumns); //if (dlg.ShowDialog() != DialogResult.OK) return; PrintTitle = dlg.PrintTitle; PrintAllRows = dlg.PrintAllRows; SelectedColumns = dlg.GetSelectedColumns(); if (dlg.PrintFont != null) PrintFont = dlg.PrintFont; if (dlg.PrintFontColor.Name != "" & dlg.PrintFontColor.Name != "0") PrintFontColor = dlg.PrintFontColor; RowsPerPage = 1; ppvw = new PrintPreviewDialog(); ppvw.Document = printDoc; // Show Print Preview Page printDoc.BeginPrint += new System.Drawing.Printing.PrintEventHandler(printDoc_BeginPrint); printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); if (ppvw.ShowDialog() != DialogResult.OK) { printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(printDoc_BeginPrint); printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); return; } // Print the Documnet printDoc.Print(); printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(printDoc_BeginPrint); printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(printDoc_PrintPage); } catch (Exception ex) { ExMessageBox.Show(ex.Message, "Lỗi", ExMessageBox.CYButtons.OK, ExMessageBox.CYIcon.Error); } finally { } }