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++;

}









share|improve this question




























    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++;

    }









    share|improve this question


























      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++;

      }









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 23:07









      halfer

      14.2k757106




      14.2k757106










      asked Nov 9 at 17:08









      djnilo

      12




      12





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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