Torna al Thread
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] = "";
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; i < 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;
Font MyFont = new Font("Arial", 15);
for (int i = 0; i < count; i++)
{
int m = 50;
m += 20;
string prova = "";
prova = gio[i] + " " + des[i] + " " + ent[i] + " " + usc[i] + " " + net[i] + " " + tot[i];
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 + 3));
/*int altezza = ev.PageSettings.PaperSize.Height;
if (m > (altezza - 150))
{
ev.Graphics.DrawString(pag.ToString(), MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m + 3));
ev.Graphics.DrawString("\f", MyFont, new SolidBrush(Color.Black), (ev.PageBounds.Left + 50), (m + 3));
m = 50;
pag++;
}*/
}
}