Место общения программистов C#
Anonymous
Печать новых страниц с помощью E.HasmorePages
Сообщение
Anonymous » 07 июл 2025, 18:39
Я немного запутался, как я могу использовать свойство HasmorePages . Я пытаюсь распечатать какую -то страницу больше в зависимости от метода yposition < /code>, но это вызывает бесконечный цикл страниц печати. < /P>
Это мой код: < /p>
Код: Выделить всё
private float YPosition()
{
return this.TopMargin + ((float)this.LinesCount * this.Font.GetHeight(this.Graphics) + (float)this.ImagesHeight);
}
private void TicketPrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
this.Graphics = e.Graphics;
foreach (Tuple tuple in this.Objects)
{
switch (tuple.Item2)
{
case LineTypes.LINE:
this.Graphics.DrawString((String)tuple.Item1, this.Font, this.SolidBrush, this.LeftMargin, this.YPosition(), new StringFormat());
this.LinesCount++;
break;
case LineTypes.IMAGE:
Image Image = (Image)tuple.Item1;
// Center Image, using PaperSize
Graphics GraphicsImage = Graphics.FromImage(Image);
RectangleF RectangleF = e.MarginBounds;
RectangleF.Offset(-e.PageSettings.HardMarginX, -e.PageSettings.HardMarginY);
float InchX = RectangleF.X / 100f + (RectangleF.Width / 100f - (float)Image.Width / GraphicsImage.DpiX) / 2f;
Int32 MillimeterX = (Int32)Math.Ceiling(InchX / 0.039370);
this.Graphics.DrawImage(Image, new Point((int)this.LeftMargin + (MillimeterX / 2), (int)this.YPosition()));
double a = (double)Image.Height / 58.0 * 15.0;
this.ImagesHeight += (int)Math.Round(a) + 3;
break;
}
if ((YPosition() * 4) >= e.PageSettings.PrintableArea.Height)
{
e.HasMorePages = true;
return;
}
else
{
e.HasMorePages = false;
}
}
}
< /code>
YPosition представляют высоту каждой строки или изображений на страницах.>
Подробнее здесь:
https://stackoverflow.com/questions/325 ... smorepages
1751902755
Anonymous
Я немного запутался, как я могу использовать свойство HasmorePages . Я пытаюсь распечатать какую -то страницу больше в зависимости от метода yposition < /code>, но это вызывает бесконечный цикл страниц печати. < /P> Это мой код: < /p> [code] private float YPosition() { return this.TopMargin + ((float)this.LinesCount * this.Font.GetHeight(this.Graphics) + (float)this.ImagesHeight); } private void TicketPrintPage(object sender, PrintPageEventArgs e) { e.Graphics.PageUnit = GraphicsUnit.Millimeter; this.Graphics = e.Graphics; foreach (Tuple tuple in this.Objects) { switch (tuple.Item2) { case LineTypes.LINE: this.Graphics.DrawString((String)tuple.Item1, this.Font, this.SolidBrush, this.LeftMargin, this.YPosition(), new StringFormat()); this.LinesCount++; break; case LineTypes.IMAGE: Image Image = (Image)tuple.Item1; // Center Image, using PaperSize Graphics GraphicsImage = Graphics.FromImage(Image); RectangleF RectangleF = e.MarginBounds; RectangleF.Offset(-e.PageSettings.HardMarginX, -e.PageSettings.HardMarginY); float InchX = RectangleF.X / 100f + (RectangleF.Width / 100f - (float)Image.Width / GraphicsImage.DpiX) / 2f; Int32 MillimeterX = (Int32)Math.Ceiling(InchX / 0.039370); this.Graphics.DrawImage(Image, new Point((int)this.LeftMargin + (MillimeterX / 2), (int)this.YPosition())); double a = (double)Image.Height / 58.0 * 15.0; this.ImagesHeight += (int)Math.Round(a) + 3; break; } if ((YPosition() * 4) >= e.PageSettings.PrintableArea.Height) { e.HasMorePages = true; return; } else { e.HasMorePages = false; } } } < /code> YPosition[/code] представляют высоту каждой строки или изображений на страницах.> Подробнее здесь: [url]https://stackoverflow.com/questions/32511364/printing-new-pages-with-e-hasmorepages[/url]