1
I want to print the various variables of a List
. I’m trying to use foreach
but it hasn’t worked. Variables are written over each other instead of a line break. Look at my code in the event printPage:
int charactersOnPage = 0;
int linesPerPage = 0;
var Fonte = new Font("Arial", 18);
Cliente cliente = Clientes[listaClientes.SelectedIndex];
foreach (var cli in cliente.Produtos)
{
string impressao = string.Format("Produto: {0}", cli.NomeProduto);
e.Graphics.MeasureString(impressao, Fonte, e.MarginBounds.Size, StringFormat.GenericTypographic, out charactersOnPage, out linesPerPage);
e.Graphics.DrawString(impressao, Fonte, Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic);
impressao = impressao.Substring(charactersOnPage);
e.HasMorePages = false;
}
I need to have as output in print preview something like:
Produto: Carro
Produto: Bicicleta
With this code of mine, the products are all shuffled on top of each other.
It’s the first time I’m studying impression.
I don’t know this print engine, but I think it’s missing a line break or something
– Caputo
Have you tried using " n" or System.Environment.Newline to break the line where desired? If you have not tried, do a test. Example, if you wanted to break the line after the product name: printed string = string.Format("Product: {0}", cli.Product name) + "n";
– Renan
@Renan yes, I tried using n but it didn’t work. System.Environment.Newline I didn’t know, I’ll take a look at it.
– M. Victor
@Caputo Yes, after trying with n unsuccessfully I came here to try to discover other methods to accomplish this line break.
– M. Victor
@Renan Environment.Newline also does not cause any effect.
– M. Victor
@Omni tried in every way you exposed, but none worked. Strings insist on getting shuffled on top of each other.
– M. Victor