Windows Develop Bookmark and Share   
 index > Windows Forms General > Panel printing in multiple pages C#
 

Panel printing in multiple pages C#

I have a windows application it contains a very long panel (nearly 5 pages) full of details. Here is my problem is when I tried to print it, only get the last section of the panel in my print preview screen. I need to get the multi page print preview. How can I get it.

Please advice


Thanks in advance,
N.Nirmalan

I attach my printClass.cs file too.
------------------------------------------


using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;

namespace PanelAdd
{
public class PrintClass
{
readonly PrintDocument printdoc1 = new PrintDocument();
readonly PrintPreviewDialog previewdlg = new PrintPreviewDialog();
Bitmap MemoryImage;

private readonly Panel panel_;

public PrintClass(Panel pnl)
{
panel_ = pnl;

printdoc1.PrintPage += (printdoc1_PrintPage);
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
}

private void GetPrintArea(Control pnl)
{
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));
}

private void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
{
var pagearea = e.PageBounds;
e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) - (panel_.Width / 2), panel_.Location.Y);
}

public void Print()
{
GetPrintArea(panel_);
previewdlg.Document = printdoc1;
previewdlg.ShowDialog();
}
}
}



Nirma
Nirma  Friday, March 27, 2009 7:45 AM
You'll have to adjust the arguments to DrawToBitmap() with AutoScrollPosition. And you have to use e.HasMorePages in the PrintPage event to get more than a single page out of the printer. The end-result isn't likely to look very good, you'll arbitrarly cut off parts of controls on the page bounds. Consider using a report generator like Crystal.
Hans Passant.
nobugz  Friday, March 27, 2009 11:17 AM
When you save your MemoryImage to a file and open it in Windows Photo and Fax viewer, is the image what you want?
JohnWein  Friday, March 27, 2009 8:57 AM
You'll have to adjust the arguments to DrawToBitmap() with AutoScrollPosition. And you have to use e.HasMorePages in the PrintPage event to get more than a single page out of the printer. The end-result isn't likely to look very good, you'll arbitrarly cut off parts of controls on the page bounds. Consider using a report generator like Crystal.
Hans Passant.
nobugz  Friday, March 27, 2009 11:17 AM

You can use google to search for other answers

Custom Search

More Threads

• Drag and drop
• how to achieve a new line character in XML
• Wait for Form to close...
• DataGrid Delete Row Problem -- EditMode=EditOnEnter
• How to close a windows form massgebox using C# program?
• Dynamic User Interface
• Serialize a Windows Form to xml
• MenuStrip Not refresh in my application
• panel moving automatically while deleting control
• PropertyGrid