Insert tab when printing

Asked

Viewed 302 times

1

I have a code to print each variable of a List. I am trying to insert a tab into these variables. Take a look at my code that is in the event printPage:

int charactersOnPage = 0;
int linesPerPage = 0;

var Fonte = new Font("Arial", 12);

Cliente cliente = Clientes[listaClientes.SelectedIndex];

StringBuilder sb = new StringBuilder();
foreach (var cli in cliente.Produtos)
{
    sb.AppendFormat("\n\n{0} R${1} Data: {2}", cli.NomeProduto, cli.ValorProduto, cli.DataCompra);
}

e.Graphics.MeasureString(sb.ToString(), Fonte, e.MarginBounds.Size, StringFormat.GenericTypographic, out charactersOnPage, out linesPerPage);

e.Graphics.DrawString(sb.ToString(), Fonte, Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic);

e.HasMorePages = false;

With this code of mine output is something like: Carro R$20000 Data: 08/11/2014. I want to insert a tab between these values and have as output this:

saída

I’ve been trying things like:

RectangleF tabulacao = new RectangleF(30, 10, 100, 122);
e.Graphics.DrawString(System.Convert.ToString(sb), Fonte, Brushes.Blue, tabulacao);
e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(tabulacao));

I’m not sure how to organize each of these variables within rectangles to make the tabulation. Any help is welcome!

  • It is a report, which will be printed?

  • Yes, all products purchased by the selected customer will be printed. My code is ready and the output as I want. The only thing I need is to insert a tab as in the example to be more organized.

  • Tabulation using Rectanglef: you need to have at least one variable to control the displacement of the Rectanglef on the X axis

  • Have you considered using any Reporting tool, or even HTML Tables to generate your report?

  • I never associated C# with HTML. I think it’s a good idea.

1 answer

1

I think the most certain is you use some report generation tool.

But if you want to try generating via HTML, for simple reports, up to one page goes well:
Puts a Webbrowser in the window, and this code:

var HTML = "<html><body><table><tr><td>OK</td></tr></body></html>";
webBrowser.NavigateToString(HTML);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.