How To Make Printer Friendly Page?
My Question iz how can we make a printer friendly page with the datagrid populated. any ideas?
Thanks in Advance
you may user a 3rd party reporting tool, or do it your self.
If you decide to do it your self take a look here:
This example demonstrates printing a DataGrid control.
private void printGrid_Click(System.Object sender, System.EventArgs e) { printDocument1.Print(); } private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(0, 0), this.Size)); this.InvokePaint(dataGrid1, myPaintArgs); }However, when I tried it in VS2005, it did appeared to be broken.
I think because VS2005 uses GDI+ rather than GDI.
So I tried the new DataGridView doing something similar, but it appears to
be broken also.
Hopefully, you are still using VS2003, or can wait till Beta 3.
C:\Inetpub\wwwroot\Project\process.aspx.cs(386): The type or namespace name 'PaintEventArgs' could not be found (are you missing a using directive or an assembly reference?)
C:\Inetpub\wwwroot\Project\process.aspx.cs(383): The type or namespace name 'printDocument1' could not be found (are you missing a using directive or an assembly reference?)
C:\Inetpub\wwwroot\Project\process.aspx.cs(386): The name 'myPaintArgs' does not exist in the class or namespace 'Project.Process'
C:\Inetpub\wwwroot\Project\process.aspx.cs(386): 'Project.Process' does not contain a definition for 'InvokePaint'
Wow, I haven't see that, unless you are using TextRenderer.DrawText for your printing. Unfortunitely TextRenderer.DrawText uses GDI while Graphics.DrawString uses GDI+. GDI drawing with our current print engine doesn't work correctly, so you'll need to use Graphics.DrawString. Let me know if that works. If that isn't the case then can you file a bug and we'll investigate it? Thanks -mark
DataGridView Program Manager
Microsoft
The method is invoked from a MainForm class that contains a DataGridView publicly exposed as: The code to invoke the printing is: The Print.Timesheet class is: using namespace {
public DataGridView DataGridView { get { return dataGridView1; } }
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{Print.Timesheet timesheetPrint = new Timex.Print.Timesheet(this);}
public void DoInvokePaint(Control paintObject, PaintEventArgs paintArgs)
{this.InvokePaint(paintObject, paintArgs);}
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Text;
{
public Timesheet(MainForm form){
mainForm = form;
_PrintDocument =
new System.Drawing.Printing.PrintDocument();_PrintDocument.PrintPage +=
new System.Drawing.Printing.PrintPageEventHandler(_PrintDocument_PrintPage);SetPrintProperties(form);
}
private Font printFont; private System.Drawing.Printing.PrintDocument _PrintDocument; public System.Drawing.Printing.PrintDocument PrintDocument { get { return _PrintDocument; } } private System.Windows.Forms.PrintDialog _PrintDialog; public System.Windows.Forms.PrintDialog PrintDialog { get { return _PrintDialog; } } private MainForm mainForm; // This method will set properties on the PrintDialog object and then display the dialog. private void SetPrintProperties(System.Windows.Forms.Form form){
_PrintDialog =
new System.Windows.Forms.PrintDialog(); // Allow the user to choose the page range he or she would like to print._PrintDialog.AllowSomePages =
true; // Show the help button._PrintDialog.ShowHelp =
true; // Set the Document property to the PrintDocument for // which the PrintPage Event has been handled. To display the // dialog, either this property or the PrinterSettings property // must be set_PrintDialog.Document =
this._PrintDocument; DialogResult result = _PrintDialog.ShowDialog();printFont =
new Font("Arial", 10, FontStyle.Regular); // If the result is OK then print the document. if (result == DialogResult.OK){
_PrintDocument.Print();
}
}
/// <summary> /// The PrintPage event is raised for each page to be printed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _PrintDocument_PrintPage(object sender, PrintPageEventArgs e){
// Insert code to render the page here. // This code will be called when the control is drawn. // The following code will render a simple message on the printed document. string text = "In document_PrintPage method."; // Draw the content.e.Graphics.DrawString(text, printFont, System.Drawing.
Brushes.Black, 10, 10); PaintEventArgs paintArgs = new PaintEventArgs(e.Graphics, new Rectangle(new Point(50, 50), new Size(400,400)));mainForm.DoInvokePaint(mainForm.DataGridView, paintArgs);
}
}
}
Try using System.Windows.Forms.Control.DrawToBitmap method: this method prints the data grid view to a bitmap.
Hope this helps.