1
I am creating a system for printing labels as follows the code:
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Image newImage;
Point ulCorner;
int x = 0;
int xn = 0;
int y = 0;
int yn = 0;
bool xativo = false;
int n = 14;
int n1 = 0;
int yPage = 0;
for (int i = 0; i < lstAdesivos.Items.Count; i++)
{
newImage = Image.FromFile(@path + "\\Modelos\\" + lstAdesivos.Items[i].Text + ".png");
if (xativo == true)
{
x = 400;
y = 0;
xativo = false;
}
ulCorner = new Point(x, y);
yPage += newImage.Size.Height;
if (yPage > e.PageBounds.Height)
{
e.HasMorePages = true;
yPage = 0;
}
e.Graphics.DrawImage(newImage, ulCorner);
if (yn == nudCartelasColuna.Value - 1)
{
yn = 0;
xativo = true;
}
else
{
y += 200;
yn += 1;
}
}
Font fonte = new Font("Verdana", 12);
e.Graphics.DrawString(tbDescricao.Text, fonte, Brushes.Black, 400, 1050);
}
What happens is that instead of just creating a new page it keeps creating many endlessly, I’d like to know what I’m doing wrong?
Where is the "e" variable declared? Is this chunk of code inside an event? would that be windows Forms, wpf, Asp.net, Asp.net MVC? be more specific please. Also take a look at this page [Ask]
– Marciano.Andrade
Win Form, inside the printDocument1_PrintPage(), I changed the code on top.
– user3434888