Size of string in a richtextbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torben Laursen

    Size of string in a richtextbox

    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

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Size of string in a richtextbox

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Torben Laursen" <does@not.workw rote in message
    news:171F0649-1C70-478A-BDD7-15B62B259F0B@mi crosoft.com...
    >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

    Comment

    • rossum

      #3
      Re: Size of string in a richtextbox

      On Wed, 20 Feb 2008 16:54:29 +0100, "Torben Laursen" <does@not.wor k>
      wrote:
      >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.Te xt = firstLine + Environment.New Line +
      secondLine + Environment.New Line;

      rossum

      Comment

      Working...