我正在申请,需要使用System.Drawing.Printing库打印票证。然后,如果有超过18个字符的换行符会降低其余内容的数量,那么我就具有所需的产品字段名称。
是的,但是它们杂乱无章。其他字段的价格,数量,金额
这是我拥有的代码
**List<string> lines = BreakIntoLines(reporte[i].ProductName);
for (int i = 0; i < lines.Count; i++)
{
e.Graphics.DrawString(lines[i], Fuente, Brushes.Black, 1, intFila);
intFila += 15;**
List<string> BreakIntoLines(string text)
{
List<string> lines = new List<string>();
string[] tokens = text.Split(" ".ToCharArray());
string line = "";
foreach (string tok in tokens)
{
if (line.Length + tok.Length > 18)
{
lines.Add(line);
line = "";
}
line += tok + " ";
}
if (line.Length > 0)
lines.Add(line);
return lines;
}
private void Repo_PrintPage(object sender, PrintPageEventArgs e)
{
var intFila = 120;
float LineasPorPagina = 60;
float CantidadPaginas = 0;
int Contador = 0;
string TituloReporte = "BOLETA N° " + reporte[0].NumDocumento.ToString();
var Fuente = new Font("Arial", 8, FontStyle.Regular);
Rectangle rectangulo = new Rectangle(1, 20, 300, 20);
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
Font FuenteTitulo = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point);
StringFormat FormatoTotales = new StringFormat();
FormatoTotales.Alignment = StringAlignment.Far;
CantidadPaginas = reporte.Count / LineasPorPagina;
var IntPagina = (int)CantidadPaginas;
var saldo = CantidadPaginas - IntPagina;
if (saldo > 0)
{
CantidadPaginas = IntPagina + 1;
}
try
{
//Pen myPen = new Pen(Color.Black, 1);
//e.Graphics.DrawRectangle(myPen, 1, 80, 500, 25);
e.Graphics.DrawString(TituloReporte, FuenteTitulo, Brushes.Black, rectangulo, stringFormat);
e.Graphics.DrawString("FECHA", Fuente, Brushes.Black, 1, 50);
e.Graphics.DrawString(": " + DateTime.Now.ToShortDateString(), Fuente, Brushes.Black, 50, 50);
e.Graphics.DrawString("HORA : " + DateTime.Now.ToShortTimeString(), Fuente, Brushes.Black, 200, 50);
e.Graphics.DrawString("CLIENTE", Fuente, Brushes.Black, 1, 65);
e.Graphics.DrawString(": " + reporte[0].NombreCliente, Fuente, Brushes.Black, 50, 65);
e.Graphics.DrawString("Venta", Fuente, Brushes.Black, 1, 80);
e.Graphics.DrawString(": " + reporte[0].IdVenta.ToString(), Fuente, Brushes.Black, 50, 80);
e.Graphics.DrawString("----------------------------------------------------------------------------------", Fuente, Brushes.Black, 1, 90);
e.Graphics.DrawString("DESCRIPCION", Fuente, Brushes.Black, 1, 100);
e.Graphics.DrawString("Precie", Fuente, Brushes.Black, 130, 100);
e.Graphics.DrawString("quantity,", Fuente, Brushes.Black, 180, 100);
e.Graphics.DrawString("amount", Fuente, Brushes.Black, 230, 100);
e.Graphics.DrawString("----------------------------------------------------------------------------------", Fuente, Brushes.Black, 1, 108);
while (Contador < LineasPorPagina && i < reporte.Count)
{
List<string> lines = BreakIntoLines(reporte[i].ProductName);
for (int i = 0; i < lines.Count; i++)
{
e.Graphics.DrawString(lines[i], Fuente, Brushes.Black, 1, intFila);
intFila += 15;
}
e.Graphics.DrawString(reporte[i].Precie.ToString("0,0.00"), Fuente, Brushes.Black, 130, intFila);
e.Graphics.DrawString(reporte[i].quantity.ToString("00"), Fuente, Brushes.Black, 190, intFila);
e.Graphics.DrawString((reporte[i].Precie * reporte[i].quantity).ToString("0,0.00"), Fuente, Brushes.Black, 280, intFila, FormatoTotales);
intFila += 15;
Contador++;
i++;
}