بســم الله الـرحمــن الرحيــم
السلام عليكــم ورحمـة الله وبركاتــه
أنني الآن أقوم بتطوير مشروع يحتوي على تقرير مؤلف من أكثر من صفحة ولكنني عند الضغط على Print Preview أحصل على صفحة واحدة من صفحات التقرير
مع العلم أنني قمت بالبحث في هذا المنتدى وحصلت على نتيجتين جديرين بالذكر الأولى
ولم يتم إجابة الأخ
والثاني
http://www.devarticles.com/c/a/C-Sharp/Pri...sing-C-sharp/4/
الشرح غير واضح تماماً وبحاجة إلى توضيح
وسوف أضع لكم الكود الخاص بالحدث PrintDocument1_PrintPage في برنامجي:
Font f1 = new Font("Times New Roman", 9);
x = PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width - 60;
// y = dgvc.Width;
foreach (DataGridViewColumn dgvc in dataGridView1.Columns)
{
if (dgvc.Visible == true)
{
// e.Graphics.DrawString(dgvc.HeaderText, f1, Brushes.Red, new PointF(x, dgvc.Width));
e.Graphics.DrawString(dgvc.HeaderText, f1, Brushes.Red, new PointF(x, dgvc.Width));
x -= dgvc.Width - 10;
y = dgvc.Width;
}
}
Decimal sumcell = 0;
int wdth = 0;
int high = 0;
int count = 0;
foreach (DataGridViewRow dgvr in dataGridView1.Rows)
{
x = PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width - 60;
y += dgvr.Height - 5;
high = dgvr.Height - 5;
foreach (DataGridViewCell dgvc in dgvr.Cells)
{
if (dgvc.Visible == true)
{
if (dgvc.Value == null)
{
}
else if (dgvc.Value.GetType() == typeof(DateTime))
{
DateTime d1 = (DateTime)dgvc.Value;
String s1 = d1.ToShortDateString();
e.Graphics.DrawString(s1, f1, Brushes.Black, new PointF(x, y));
}
else if (dgvc.ColumnIndex == 11)
{
sumcell += Decimal.Parse (dgvc.Value.ToString());
e.Graphics.DrawString(dgvc.Value.ToString(), f1, Brushes.Black, new PointF(x, y));
}
else
{
e.Graphics.DrawString(dgvc.Value.ToString(), f1, Brushes.Black, new PointF(x, y));
}
x -= dgvc.Size.Width - 10;
wdth = dgvc.Size.Width - 10;
}
}
count++;
}
x = PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width - 60;
y += ((high)*count) -5;
x -= (wdth) * 5;
e.Graphics.DrawString(":المجموع", f1, Brushes.Black, new PointF(x, y));
x = PrintDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width - 60;
x -= (wdth) * 6;
e.Graphics.DrawString(sumcell.ToString(), f1, Brushes.Black, new PointF(x, y));والكود الخاص بالزر Print_Preview
try
{
PrintPreviewDialog1.Document = PrintDocument1;
PrintPreviewDialog1.ShowDialog();
}
catch (Exception exp)
{
MessageBox.Show(exp + "An error occurred while trying to load the " +
"access to a printer. A printer must be connected and " +
"accessible for Print Preview to work.");
}وشكراً لكم
والسلام عليكم.