Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi How to make a table of DataGridView information printed right to left?

[EDIT - OP code from comment]
C#
// The printing setup function
 private bool SetupThePrinting()
 {
     PrintDialog MyPrintDialog = new PrintDialog();
     MyPrintDialog.AllowCurrentPage = false;
     MyPrintDialog.AllowPrintToFile = false;
     MyPrintDialog.AllowSelection = false;
     MyPrintDialog.AllowSomePages = false;
     MyPrintDialog.PrintToFile = false;
     MyPrintDialog.ShowHelp = false;
     MyPrintDialog.ShowNetwork = false;

     if (MyPrintDialog.ShowDialog() != DialogResult.OK)
     return false;

     MyPrintDocument.DocumentName = "Customers Report";
     MyPrintDocument.PrinterSettings =
     MyPrintDialog.PrinterSettings;
     MyPrintDocument.DefaultPageSettings =
     MyPrintDialog.PrinterSettings.DefaultPageSettings;
     MyPrintDocument.DefaultPageSettings.Margins =
     new Margins(40, 40, 40, 40);

     if (MessageBox.Show("Do you want the report to be centered on the page",
            "InvoiceManager - Center on Page", MessageBoxButtons.YesNo,
            MessageBoxIcon.Question) == DialogResult.Yes)
        MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView, MyPrintDocument, true, true, "Customers", new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);
     else
        MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView, MyPrintDocument, false, true, "Customers", new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);

     return true;


 // The Print Button
 private void btnPrint_Click(object sender, EventArgs e)
 {
    if (SetupThePrinting())
    MyPrintDocument.Print();
 }

C#
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Data;
using System.Windows.Forms;

class DataGridViewPrinter
{
   // The DataGridView Control which will be printed
   private DataGridView TheDataGridView;
   // The PrintDocument to be used for printing
   private PrintDocument ThePrintDocument;
   // Determine if the report will be
   // printed in the Top-Center of the page
   private bool IsCenterOnPage;
   // Determine if the page contain title text
   private bool IsWithTitle;
   // The title text to be printed
   // in each page (if IsWithTitle is set to true)
   private string TheTitleText;
   // The font to be used with the title
   // text (if IsWithTitle is set to true)
   private Font TheTitleFont;
   // The color to be used with the title
   // text (if IsWithTitle is set to true)
   private Color TheTitleColor;
   // Determine if paging is used
   private bool IsWithPaging;

   // A static parameter that keep track
   // on which Row (in the DataGridView control)
   // that should be printed
   static int CurrentRow;

   static int PageNumber;

   private int PageWidth;
   private int PageHeight;
   private int LeftMargin;
   private int TopMargin;
   private int RightMargin;
   private int BottomMargin;

   // A parameter that keep track
   // on the y coordinate of the page,
   // so the next object to be printed
   // will start from this y coordinate
   private float CurrentY;

   private float RowHeaderHeight;
   private List RowsHeight;
   private List ColumnsWidth;
   private float TheDataGridViewWidth;

   // Maintain a generic list to hold start/stop
   // points for the column printing
   // This will be used for wrapping
   // in situations where the DataGridView will not
   // fit

   public DataGridViewPrinter(DataGridView aDataGridView, PrintDocument aPrintDocument,
   bool CenterOnPage, bool WithTitle, string aTitleText, Font aTitleFont,
   Color aTitleColor, bool WithPaging)

   // The DataGridView Control which will be printed.
   DataGridView MyDataGridView;
   // The PrintDocument to be used for printing.
   PrintDocument MyPrintDocument;
   // The class that will do the printing process.
   DataGridViewPrinter MyDataGridViewPrinter;
Posted
Updated 27-May-14 23:26pm
v2
Comments
CHill60 28-May-14 4:02am    
Not at all clear. Use the Improve question link to provide more information. Include the code you have tried so far
Mehdi Formi 28-May-14 4:18am    
public DataGridViewPrinter(DataGridView aDataGridView, PrintDocument aPrintDocument,
bool CenterOnPage, bool WithTitle, string aTitleText, Font aTitleFont,
Color aTitleColor, bool WithPaging)

// The DataGridView Control which will be printed.
DataGridView MyDataGridView;
// The PrintDocument to be used for printing.
PrintDocument MyPrintDocument;
// The class that will do the printing process.
DataGridViewPrinter MyDataGridViewPrinter;



/ The printing setup function
private bool SetupThePrinting()
{
PrintDialog MyPrintDialog = new PrintDialog();
MyPrintDialog.AllowCurrentPage = false;
MyPrintDialog.AllowPrintToFile = false;
MyPrintDialog.AllowSelection = false;
MyPrintDialog.AllowSomePages = false;
MyPrintDialog.PrintToFile = false;
MyPrintDialog.ShowHelp = false;
MyPrintDialog.ShowNetwork = false;

if (MyPrintDialog.ShowDialog() != DialogResult.OK)
return false;

MyPrintDocument.DocumentName = "Customers Report";
MyPrintDocument.PrinterSettings =
MyPrintDialog.PrinterSettings;
MyPrintDocument.DefaultPageSettings =
MyPrintDialog.PrinterSettings.DefaultPageSettings;
MyPrintDocument.DefaultPageSettings.Margins =
new Margins(40, 40, 40, 40);

if (MessageBox.Show("Do you want the report to be centered on the page",
"InvoiceManager - Center on Page", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView,
MyPrintDocument, true, true, "Customers", new Font("Tahoma", 18,
FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);
else
MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView,
MyPrintDocument, false, true, "Customers", new Font("Tahoma", 18,
FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);

return true;


// The Print Button
private void btnPrint_Click(object sender, EventArgs e)
{
if (SetupThePrinting())
MyPrintDocument.Print();
}

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Data;
using System.Windows.Forms;

class DataGridViewPrinter
{
// The DataGridView Control which will be printed
private DataGridView TheDataGridView;
// The PrintDocument to be used for printing
private PrintDocument ThePrintDocument;
// Determine if the report will be
// printed in the Top-Center of the page
private bool IsCenterOnPage;
// Determine if the page contain title text
private bool IsWithTitle;
// The title text to be printed
// in each page (if IsWithTitle is set to true)
private string TheTitleText;
// The font to be used with the title
// text (if IsWithTitle is set to true)
private Font TheTitleFont;
// The color to be used with the title
// text (if IsWithTitle is set to true)
private Color TheTitleColor;
// Determine if paging is used
private bool IsWithPaging;

// A static parameter that keep track
// on which Row (in the DataGridView control)
// that should be printed
static int CurrentRow;

static int PageNumber;

private int PageWidth;
private int PageHeight;
private int LeftMargin;
private int TopMargin;
private int RightMargin;
private int BottomMargin;

// A parameter that keep track
// on the y coordinate of the page,
// so the next object to be printed
// will start from this y coordinate
private float CurrentY;

private float RowHeaderHeight;
private List<float> RowsHeight;
private List<float> ColumnsWidth;
private float TheDataGridViewWidth;

// Maintain a generic list to hold start/stop
// points for the column printing
// This will be used for wrapping
// in situations where the DataGridView will not
// fit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900