|
I liked the code. But I am still demanding your support on how I can add the "hasMorePages" . Thank you
|
|
|
|
|
Very thanks. İts worked. I am search all web but this code solved my problem.
|
|
|
|
|
I am using your code. I have 6 digit number and for first two digit its draws ellipse correctly but for the other one it is overprinting on the previous one. I thought i have used return; that caused problems because it recalls the function. Please help me
|
|
|
|
|
Your problem is not clear. Elaborate your problem.
--
Animesh
|
|
|
|
|
If we start program more than once, program prints blank pages.
To avoid that, add two lines at the end of printDocument1_PrintPage event handler :
totalnumber = 0;
itemperpage = 0;
This will reset counters to initial values, and program will work fine.
Thanks for program code, it was very useful.
All the best,
Perić Željko
|
|
|
|
|
To anyone,
What am I missing?
When I click Print preview, it popups a new screen correctly and shows the pages. When I click Print button it popups a selection for printer. I select the printer and the popup disappears and no output is sent to the printer or file if I change the options.
I modified the paperSize("papersize", 550, 900) and I am print from DataTable and header information. This is displayed in the preview but the print button does not do the same.
The dba.getDataTableFromGrid(gvFormat) is a method to put gridview values into Datatable and dba is the class.
Code follows:
Controls
prntFileDialog is PrintDialog1
prntPrevFileDialog is PrintPreviewDialog1
prntFileFormat is PrintDocument1
int totalnumber = 0;
int itemperpage = 0;
DataTable printDt = null;
int printRow = 0;
private void btnPrintPrev_Click(object sender, EventArgs e)
{
totalnumber = itemperpage = printRow = 0;
prntPrevFileDialog.Document = prntFileFormat;
// Disable the direct print from printpreview as when we click that
// Print button PrintPage event fires again
((ToolStripButton)((ToolStrip)prntPrevFileDialog.Controls[1]).Items[0]).Enabled = false;
prntFileFormat.DefaultPageSettings.PaperSize = paperSize;
DBAccess dba = new DBAccess("");
printDt = new DataTable();
printDt = dba.getDataTableFromGrid(gvFormat);
prntPrevFileDialog.ShowDialog();
}
private void btnPrint_Click(object sender, EventArgs e)
{
totalnumber = itemperpage = printRow = 0;
prntFileDialog.Document = prntFileFormat;
prntFileFormat.DefaultPageSettings.PaperSize = paperSize;
DBAccess dba = new DBAccess("");
printDt = new DataTable();
printDt = dba.getDataTableFromGrid(gvFormat);
prntFileDialog.ShowDialog();
}
private void prntFileFormat_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString("File Format", new Font("Calibra", 12, FontStyle.Bold), Brushes.Black, new Point(350,25));
e.Graphics.DrawString("Customer: " + cboCustomer.Text, new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(60, 50));
e.Graphics.DrawString("Transaction Set: " + cboTrans.Text, new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(15, 75));
e.Graphics.DrawString("Record Type: " + cboRecordType.Text, new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(40, 100));
e.Graphics.DrawString("No", new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(25, 150));
e.Graphics.DrawString("Field Name", new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(75, 150));
e.Graphics.DrawString("Delim", new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(250, 150));
e.Graphics.DrawString("Size", new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(300, 150));
e.Graphics.DrawString("Range", new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(350, 150));
e.Graphics.DrawString(lblUnderline.Text, new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(25, 175));
while (printRow < printDt.Rows.Count)
{
if (!string.IsNullOrEmpty(printDt.Rows[printRow][0].ToString()))
{
e.Graphics.DrawString(printDt.Rows[printRow][0].ToString(), new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(25, itemperpage * 25 + 200));
e.Graphics.DrawString(printDt.Rows[printRow][1].ToString(), new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(75, itemperpage * 25 + 200));
e.Graphics.DrawString(printDt.Rows[printRow][2].ToString(), new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(250, itemperpage * 25 + 200));
e.Graphics.DrawString(printDt.Rows[printRow][3].ToString(), new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(300, itemperpage * 25 + 200));
e.Graphics.DrawString(printDt.Rows[printRow][4].ToString(), new Font("Calibra", 12, FontStyle.Regular), Brushes.Black, new Point(350, itemperpage * 25 + 200));
}
if (itemperpage < 26)
{
itemperpage += 1;
e.HasMorePages = false;
}
else
{
itemperpage = 0;
e.HasMorePages = true;
return;
}
printRow++;
}
}
|
|
|
|
|
I agree. Print preview works fine, but Print does not work at all. I set breakpoint in printDocument1_PrintPage, and it is only reached during Print Preview, not during Print. I get Print dialog, but after choosing any printer and clicking Print, nothing is printed, and printDocument1_PrintPage is not reached.
Additionally from functional standpoint, the Print Preview dialog has a Print button which is grayed out -- that button should be enabled and should have the Print dialog opening.
In case it matters, I am targeting .NET Framework 4.
|
|
|
|
|
Hello,
Actually in both cases(for Preview and Print) I am showing the Print Preview option.To print a page check the code should be like this
private void bnprint_Click(object sender, EventArgs e)
{
itemperpage = totalnumber = 0;
printDialog1.Document =printDocument1;
printDocument1.DefaultPageSettings.PaperSize = paperSize;
if (printDialog1.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
Thank You
--
Animesh
|
|
|
|
|
With a little work to clean things up for my situation your code worked fine - thanks.
|
|
|
|
|
Hello ,
Sorry for late response .I have already mentioned in the tip that you have to take two global variable to track the page height and number of items of the print document .But where you have set "ItemPerPage" variable in the code ? Beside that i is initialing everytime from 0 . hence the error is coming .
Try by this way
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
for (int i = totalnumber; i < dt.Rows.Count ; i++)
{
totalnumber += 1
if(itemperpage<1)
{
itemperpage+=1
e.HasMorePages = false;
}
else
{
itemperpage=0
e.HasMorePages = true;
return;
}
}
}
Hope this helps you
|
|
|
|
|
Hello.
I am using same keywords, logic and concept to print multiple pages but it is not printing all pages,. I want to print one record on 1 page. I have 5 records and it is printing only 1st records 5 times.
If i remove return; inside if then it prints only 2 pages on first page it prints all the numbers again and again and on 2nd page only 1st number is printed one time. You can check my question in detail at
[^]
Please tell me what should i do to solve this
Thanks
|
|
|
|