I'm creating a system for printing labels as follows:
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 creates many infinitely, would you like to know what I'm doing wrong?