Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Stampa Visual C#
giovedì 24 dicembre 2009 - 00.45
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
AndreaR1981
Profilo
| Newbie
2
messaggi | Data Invio:
gio 24 dic 2009 - 00:45
Salve.
ho provato in tutti i modi ma non riesco a stampare tutte le righe presenti su delle listbox sulla stampante predefinita.
ecco il codice che utilizzo:
private void button5_Click(object sender, EventArgs e)
{
int[] cou = new int[6];
cou[0] = listBox1.Items.Count;
cou[1] = listBox2.Items.Count;
cou[2] = listBox3.Items.Count;
cou[3] = listBox4.Items.Count;
cou[4] = listBox5.Items.Count;
cou[5] = listBox6.Items.Count;
int count = cou[0];
for (int i = 1; i < 6; i++)
{
if (count < cou[i])
{
count = cou[i];
}
}
string[] des = new string[count];
string[] gio = new string[count];
string[] ent = new string[count];
string[] usc = new string[count];
string[] net = new string[count];
string[] tot = new string[count];
listBox1.Items.CopyTo(des, 0);
listBox2.Items.CopyTo(ent, 0);
listBox3.Items.CopyTo(usc, 0);
listBox4.Items.CopyTo(net, 0);
listBox5.Items.CopyTo(tot, 0);
listBox6.Items.CopyTo(gio, 0);
PrintDocument prdoc = new PrintDocument();
prdoc.PrintPage += new PrintPageEventHandler(this.PrintPageEvent);
prdoc.Print();
}
private void PrintPageEvent(object sender, PrintPageEventArgs ev)
{
int[] cou = new int[6];
cou[0] = listBox1.Items.Count;
cou[1] = listBox2.Items.Count;
cou[2] = listBox3.Items.Count;
cou[3] = listBox4.Items.Count;
cou[4] = listBox5.Items.Count;
cou[5] = listBox6.Items.Count;
int count = cou[0];
for (int i = 1; i < 6; i++)
{
if (count < cou[i])
{
count = cou[i];
}
}
string[] des = new string[count];
string[] gio = new string[count];
string[] ent = new string[count];
string[] usc = new string[count];
string[] net = new string[count];
string[] tot = new string[count];
listBox1.Items.CopyTo(des, 0);
listBox2.Items.CopyTo(ent, 0);
listBox3.Items.CopyTo(usc, 0);
listBox4.Items.CopyTo(net, 0);
listBox5.Items.CopyTo(tot, 0);
listBox6.Items.CopyTo(gio, 0);
int maxdes = des[0].Length;
int maxent = ent[0].Length;
int maxusc = usc[0].Length;
int maxnet = net[0].Length;
int maxtot = tot[0].Length;
string[] desspazi = new string[count];
string[] entspazi = new string[count];
string[] uscspazi = new string[count];
string[] netspazi = new string[count];
string[] totspazi = new string[count];
for (int i = 1; i < count; i++)
{
if (maxdes < des[i].Length)
{
maxdes = des[i].Length;
}
if (maxent < ent[i].Length)
{
maxent = ent[i].Length;
}
if (maxusc < usc[i].Length)
{
maxusc = usc[i].Length;
}
if (maxnet < net[i].Length)
{
maxnet = net[i].Length;
}
if (maxtot < tot[i].Length)
{
maxtot = tot[i].Length;
}
}
int diff = 0;
for (int i = 0; i < count; i++)
{
diff = maxdes - des[i].Length;
desspazi[i] = "";
if (des[i].Length == 0)
{
desspazi[i] += "\t";
}
else
{
for (int j = 0; j < diff; j++)
{
desspazi[i] = desspazi[i] + " ";
}
}
}
diff = 0;
for (int i = 0; i < count; i++)
{
diff = maxent - ent[i].Length;
entspazi[i] = "";
for (int j = 0; j < diff; j++)
{
entspazi[i] += " ";
}
}
diff = 0;
for (int i = 0; i < count; i++)
{
diff = maxusc - usc[i].Length;
uscspazi[i] = "";
for (int j = 0; j < diff; j++)
{
uscspazi[i] += " ";
}
}
diff = 0;
for (int i = 0; i < count; i++)
{
diff = maxnet - net[i].Length;
netspazi[i] = "";
for (int j = 0; j < diff; j++)
{
netspazi[i] += " ";
}
}
diff = 0;
for (int i = 0; i < count; i++)
{
diff = maxtot - tot[i].Length;
uscspazi[i] = "";
for (int j = 0; j < diff; j++)
{
uscspazi[i] += " ";
}
}
for (int i = 0; i < count; i++)
{
des[i] += desspazi[i];
ent[i] += entspazi[i];
usc[i] += uscspazi[i];
tot[i] += totspazi[i];
net[i] += netspazi[i];
}
int pag = 1;
float coud = count / 52;
Font MyFont = new Font("Arial", 15);
int m = 70;
ev.HasMorePages = true;
int g = 0;
ev.Graphics.DrawString("Giorno \t\t\tDescrizione\tEntrate\tUscite\tNetto\tTotale Sig.", MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m));
m += 20;
for (int j = 0; j < count; j++)
{
g++;
m += 20;
string prova = "";
prova = gio[j] + "\t" + des[j] + "\t" + ent[j] + "\t" + usc[j] + "\t" + net[j] + "\t" + tot[j];
ev.Graphics.DrawString(prova, MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m));
ev.Graphics.DrawString("\n", MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m));
if (pag < coud)
{
m += 20;
ev.Graphics.DrawString(pag.ToString(), MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m));
ev.Graphics.DrawString("\f", MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m + 3));
m = 70;
pag++;
}
else
{
ev.HasMorePages = false;
}
}
m += 20;
ev.Graphics.DrawString("Tot. Inc. : " + textBox5.Text + " Tot. Entr. : " + textBox1.Text + " Tot. Usc. : " + textBox2.Text + " Tot. Netto : " + textBox3.Text + " Tot. Sig.: " + textBox4.Text, MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m));
int altezza = ev.PageSettings.PaperSize.Height;
}
il problema di questo codice è che mi stampa tutte le righe su un'unica pagina mentre dovrebbe stampare su tutte le pagine necessarie.
Andrea.
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !