Esempio n. 1
0
        public static void Print_DataGridView(DataGridView dgv1)
        {
            PrintPreviewDialog ppvw;

            try
            {
                // Getting DataGridView object to print
                dgv = dgv1;

                // Getting all Coulmns Names in the DataGridView
                AvailableColumns.Clear();
                foreach (DataGridViewColumn c in dgv.Columns)
                {
                    if (!c.Visible)
                    {
                        continue;
                    }
                    AvailableColumns.Add(c.HeaderText);
                }

                // Showing the PrintOption Form
                PrintOptions dlg = new PrintOptions(AvailableColumns);
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                PrintTitle      = dlg.PrintTitle;
                PrintAllRows    = dlg.PrintAllRows;
                FitToPageWidth  = dlg.FitToPageWidth;
                SelectedColumns = dlg.GetSelectedColumns();

                RowsPerPage = 0;

                ppvw          = new PrintPreviewDialog();
                ppvw.Document = printDoc;

                // Showing the 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;
                }

                // Printing 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)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
            }
        }
Esempio n. 2
0
        private static int TotalWidth; // Summation of Columns widths

        #endregion Fields

        #region Methods

        public static void Print_DataGridView(DataGridView dgv1)
        {
            PrintPreviewDialog ppvw;
            try
            {
                // Getting DataGridView object to print
                dgv = dgv1;

                // Getting all Coulmns Names in the DataGridView
                AvailableColumns.Clear();
                foreach (DataGridViewColumn c in dgv.Columns)
                {
                    if (!c.Visible) continue;
                    AvailableColumns.Add(c.HeaderText);
                }

                // Showing the PrintOption Form
                PrintOptions dlg = new PrintOptions(AvailableColumns);
                if (dlg.ShowDialog() != DialogResult.OK) return;

                PrintTitle = dlg.PrintTitle;
                PrintAllRows = dlg.PrintAllRows;
                FitToPageWidth = dlg.FitToPageWidth;
                SelectedColumns = dlg.GetSelectedColumns();

                RowsPerPage = 0;

                ppvw = new PrintPreviewDialog();
                ppvw.Document = printDoc;

                // Showing the 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;
                }

                // Printing 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)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {

            }
        }
Esempio n. 3
0
 public static void Print_DataGridView(DataGridView dgv1, string title)
 {
     try
     {
         try
         {
             dataGridView_0 = dgv1;
             list_1.Clear();
             foreach (DataGridViewColumn column in dataGridView_0.Columns)
             {
                 if (column.Visible)
                 {
                     list_1.Add(column.HeaderText);
                 }
             }
             PrintOptions options = new PrintOptions(list_1)
             {
                 PrintTitle = string_0
             };
             if (options.ShowDialog() == DialogResult.OK)
             {
                 string_0 = options.PrintTitle;
                 bool_1   = options.PrintAllRows;
                 bool_2   = options.FitToPageWidth;
                 list_0   = options.GetSelectedColumns();
                 int_4    = 0;
                 PrintPreviewDialog dialog = new PrintPreviewDialog {
                     Document = printDocument_0
                 };
                 printDocument_0.BeginPrint += new PrintEventHandler(PrintDGV.smethod_0);
                 printDocument_0.PrintPage  += new PrintPageEventHandler(PrintDGV.smethod_1);
                 if (dialog.ShowDialog() != DialogResult.OK)
                 {
                     printDocument_0.BeginPrint -= new PrintEventHandler(PrintDGV.smethod_0);
                     printDocument_0.PrintPage  -= new PrintPageEventHandler(PrintDGV.smethod_1);
                 }
                 else
                 {
                     printDocument_0.Print();
                     printDocument_0.BeginPrint -= new PrintEventHandler(PrintDGV.smethod_0);
                     printDocument_0.PrintPage  -= new PrintPageEventHandler(PrintDGV.smethod_1);
                 }
             }
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         }
     }
     finally
     {
     }
 }