Hallo,
Ich habe eine Frage.
Ich habe meinen PrintPage-Event folgenderweise erstellt.
Wird eine Seite problemlos gedruckt, wenn aber das Text über Mehrere Seiten hingeht dann wird noch eine Zusätzliche leere Seite bloß mit dem Logo-Bild gedruckt.
Woran liegt es? Was mache ich falsch?
[highlight=c#]
void myPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
e.HasMorePages = true;
int items = 0, subItems = 390, lineCount = 0;
// Logo
Bitmap imagetoprint = (Bitmap)this.Logo.Image;
//graphics object
Graphics gr = e.Graphics;
// my Font Nr.1
System.Drawing.Font fnt = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
// my Font Nr.2
System.Drawing.Font fntBold = new System.Drawing.Font("Times New Roman", 12, FontStyle.Bold);
Brush br = Brushes.Black;
// Header
gr.DrawImage(imagetoprint, 550, 60, 177, 59);
gr.DrawString("my Name", fnt, br, 60, 80); // Address
gr.DrawString("Strasse", fnt, br, 60, 100);
gr.DrawString("Ort", fnt, br, 60, 130);
string t2 = "Datum:"+ '\t'+ dateTimePicker1.Text;
gr.DrawString(t2, fnt, br, 60, 200);
string t3 = "Erfassungsort:" + '\t' + this.cmbBoxErfassung.Text;
gr.DrawString(t3, fnt, br, 60, 220);
string t6 = "Sachbearbeiter:" + '\t' + cmbBoxSachbearbeiter.Text;
gr.DrawString(t6, fnt, br, 60, 240);
string t4 = "Auftrag - Nr.: " + this.txtBAuftrag.Text;
gr.DrawString(t4, fntBold, br, 60, 280);
string t5 = "Lieferschein: " + this.txtBLieferSchein.Text;
gr.DrawString(t5, fntBold, br, 60, 300);
int[] myPixelNumber = new int[7] { 60, 135, 212, 332, 412, 492, 832 }; // Einen Array für feste Abstand zvischen Items
//ColumnsHeader aus ListView auslesen und zeichnen
foreach (ColumnHeader cH in listView1.Columns)
{
gr.DrawString(cH.Text, fnt, br, myPixelNumber[items], 350);
items++;
}
Pen myPen = new Pen(br);
PointF a1 = new PointF(60,370);
PointF a2 = new PointF(800,370);
gr.DrawLine(myPen,a1,a2);// Eine Trennlinie zeichnen
// Items und Subitems aus ListView auslesen und zeichnen
foreach (ListViewItem lvi in listView1.Items)
{
items = 0;
lineCount++;
foreach (ListViewItem.ListViewSubItem lvi2 in lvi.SubItems)
{
gr.DrawString(lvi2.Text, fnt, br, myPixelNumber[items], subItems);
items++;
}
subItems += 20;
}
}
catch (System.Exception printExc)
{
MessageBox.Show(printExc.Source + ": " + printExc.Message);
}
finally
{
e.HasMorePages = false;
fnt.Dispose();
fntBold.Dispose();
br.Dispose();
}
}
[/highlight]
Ich habe eine Frage.
Ich habe meinen PrintPage-Event folgenderweise erstellt.
Wird eine Seite problemlos gedruckt, wenn aber das Text über Mehrere Seiten hingeht dann wird noch eine Zusätzliche leere Seite bloß mit dem Logo-Bild gedruckt.
Woran liegt es? Was mache ich falsch?
[highlight=c#]
void myPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
e.HasMorePages = true;
int items = 0, subItems = 390, lineCount = 0;
// Logo
Bitmap imagetoprint = (Bitmap)this.Logo.Image;
//graphics object
Graphics gr = e.Graphics;
// my Font Nr.1
System.Drawing.Font fnt = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
// my Font Nr.2
System.Drawing.Font fntBold = new System.Drawing.Font("Times New Roman", 12, FontStyle.Bold);
Brush br = Brushes.Black;
// Header
gr.DrawImage(imagetoprint, 550, 60, 177, 59);
gr.DrawString("my Name", fnt, br, 60, 80); // Address
gr.DrawString("Strasse", fnt, br, 60, 100);
gr.DrawString("Ort", fnt, br, 60, 130);
string t2 = "Datum:"+ '\t'+ dateTimePicker1.Text;
gr.DrawString(t2, fnt, br, 60, 200);
string t3 = "Erfassungsort:" + '\t' + this.cmbBoxErfassung.Text;
gr.DrawString(t3, fnt, br, 60, 220);
string t6 = "Sachbearbeiter:" + '\t' + cmbBoxSachbearbeiter.Text;
gr.DrawString(t6, fnt, br, 60, 240);
string t4 = "Auftrag - Nr.: " + this.txtBAuftrag.Text;
gr.DrawString(t4, fntBold, br, 60, 280);
string t5 = "Lieferschein: " + this.txtBLieferSchein.Text;
gr.DrawString(t5, fntBold, br, 60, 300);
int[] myPixelNumber = new int[7] { 60, 135, 212, 332, 412, 492, 832 }; // Einen Array für feste Abstand zvischen Items
//ColumnsHeader aus ListView auslesen und zeichnen
foreach (ColumnHeader cH in listView1.Columns)
{
gr.DrawString(cH.Text, fnt, br, myPixelNumber[items], 350);
items++;
}
Pen myPen = new Pen(br);
PointF a1 = new PointF(60,370);
PointF a2 = new PointF(800,370);
gr.DrawLine(myPen,a1,a2);// Eine Trennlinie zeichnen
// Items und Subitems aus ListView auslesen und zeichnen
foreach (ListViewItem lvi in listView1.Items)
{
items = 0;
lineCount++;
foreach (ListViewItem.ListViewSubItem lvi2 in lvi.SubItems)
{
gr.DrawString(lvi2.Text, fnt, br, myPixelNumber[items], subItems);
items++;
}
subItems += 20;
}
}
catch (System.Exception printExc)
{
MessageBox.Show(printExc.Source + ": " + printExc.Message);
}
finally
{
e.HasMorePages = false;
fnt.Dispose();
fntBold.Dispose();
br.Dispose();
}
}
[/highlight]
Comment