System.Drawing.Printing align price amount amount
up vote
0
down vote
favorite
I am making an application and I need to print a ticket using the System.Drawing.Printing library. Then I have the product field name that I need if it has more than 18 characters that make a line break that lowers the rest of the content.
That's right, but they are disorganized. The other fields price, quantity, amount

This the code that I have
**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++;
}
alignment price
add a comment |
up vote
0
down vote
favorite
I am making an application and I need to print a ticket using the System.Drawing.Printing library. Then I have the product field name that I need if it has more than 18 characters that make a line break that lowers the rest of the content.
That's right, but they are disorganized. The other fields price, quantity, amount

This the code that I have
**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++;
}
alignment price
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am making an application and I need to print a ticket using the System.Drawing.Printing library. Then I have the product field name that I need if it has more than 18 characters that make a line break that lowers the rest of the content.
That's right, but they are disorganized. The other fields price, quantity, amount

This the code that I have
**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++;
}
alignment price
I am making an application and I need to print a ticket using the System.Drawing.Printing library. Then I have the product field name that I need if it has more than 18 characters that make a line break that lowers the rest of the content.
That's right, but they are disorganized. The other fields price, quantity, amount

This the code that I have
**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++;
}
alignment price
alignment price
edited Nov 10 at 23:07
halfer
14.2k757106
14.2k757106
asked Nov 9 at 17:08
djnilo
12
12
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230349%2fsystem-drawing-printing-align-price-amount-amount%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown