Size of string in a richtextbox

T

Torben Laursen

I have a problem with showing text in a richtextbox
I want to show 3 columns of data and want them to be aligned.
I make sure each string for each column is the same length but since
different characters take up different space in the richtextbox
the columns look like a mess.
It there a simple method to get 2 string to takeup the same space in a
richtextbox?
Example:
Entropy [kJ/(Kg Kelvin)] -8.2602E-002
Heat capacity (Cp) [kJ/(kelvin kg)] 3.0876E+000

The text is first column and the numbers are the second column

Thanks Torben
 
N

Nicholas Paldino [.NET/C# MVP]

Torben,

Well, you could use a fixed-width font. That will ensure that you can
use spaces to line up the content. Otherwise, you will have to position the
separate elements yourself.
 
R

rossum

I have a problem with showing text in a richtextbox
I want to show 3 columns of data and want them to be aligned.
I make sure each string for each column is the same length but since
different characters take up different space in the richtextbox
the columns look like a mess.
It there a simple method to get 2 string to takeup the same space in a
richtextbox?
Example:
Entropy [kJ/(Kg Kelvin)] -8.2602E-002
Heat capacity (Cp) [kJ/(kelvin kg)] 3.0876E+000

The text is first column and the numbers are the second column

Thanks Torben
Have you tried using tabs '\t'?

string firstLine = "Entropy [kJ/(Kg Kelvin)]\t\t-8.2602E-002";
string secondLine = "Heat capacity (Cp) [kJ/(kelvin kg)]\t " +
3.0876E+000";
richTextBox1.Text = firstLine + Environment.NewLine +
secondLine + Environment.NewLine;

rossum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top