Format Windows Forms text

Asked

Viewed 331 times

0

I have a system and I need to justify the text to the left, I have tried with the textbox and with ritchtext and neither of the two give me this option, I can only align the left, but when I align only the first column of text is aligned, the others follow the alignment and mess, the ideal would be I justify the left because the columns would be all aligned.Coluna bagunçada

1 answer

2


You can do the following, on the property TextAlign of TextBox you put as left.

When filling in the TextBox leave your string formatted, ex:

public static void Main()
{
  string[] names = { "Adam", "Bridgette", "Carla", "Daniel", "Ebenezer","Francine", "George" };
  decimal[] hours = { 40, 6.667m, 40.39m, 82, 40.333m, 80, 16.75m };

  Console.WriteLine("{0,-20} {1,5}\n", "Name", "Hours");

  for (int ctr = 0; ctr < names.Length; ctr++)
     Console.WriteLine("{0,-20} {1,5:N1}", names[ctr], hours[ctr]);

}

Upshot:

// The example displays the following output:
//       Name                 Hours
//
//       Adam                  40.0
//       Bridgette              6.7
//       Carla                 40.4
//       Daniel                82.0
//       Ebenezer              40.3
//       Francine              80.0
//       George                16.8

Source: Here

  • The problem is that I am not typing, this text comes from a document that I take and convert, the program serves to add some fields and parameters to the document.

  • I understand, but this code is just an example. When you read the document do the formatting on it before playing for Textbox.

Browser other questions tagged

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