Textbox Problem

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

    #1

    Textbox Problem

    Hi NG,

    I want to pass a very long string to a multilined TextBox. After doing this,
    I want to resize the TextBox vertically, so that the text fits into the
    TextBox exactly. Any ideas? I need it for a custom MessageBox.

    Thank you

    Rudi


  • Ignacio Machin

    #2
    Re: Textbox Problem

    Hi,

    I do not understand clearly what you are trying to do, but I can give you a
    few suggestion, first of all, if it's for a MessageBox you should use a
    Label instead of a TextBox , use the TextBox only if the user can change the
    Text.
    You can format the text of the message, I remember I did that once in
    javascript you could insert \n at certain points to force a correct display
    of the message, later you can know how many lines the message has by
    counting the \n.

    Hope this help,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "DotNetJunk ie" <dotnetjunkie@g mx.net> wrote in message
    news:OlTfiL5gDH A.1952@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi NG,
    >
    > I want to pass a very long string to a multilined TextBox. After doing[/color]
    this,[color=blue]
    > I want to resize the TextBox vertically, so that the text fits into the
    > TextBox exactly. Any ideas? I need it for a custom MessageBox.
    >
    > Thank you
    >
    > Rudi
    >
    >[/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Textbox Problem

      Rudi,

      I think that the calculation for this might not be so simple. You can probably call the MeasureString method on the Graphics class, and then check to see how many lines you will need based on the length of your text (you can approximate based on the number of pixels long, and all fonts have a consistent height). However, this is not exact. If you want to be exact, then you need to have an algorithm that will separate the words and see how many you can fit on each line, and then figure out how many lines you need based on the words.

      Hope this helps.

      -Nicholas Paldino [.NET/C# MVP]
      -nick{dot]paldino=at^exis consulting-dot?com

      On Thu, 25 Sep 2003 20:26:57 +0200, DotNetJunkie <dotnetjunkie@g mx.net> wrote:
      [color=blue]
      > Hi NG,
      >
      > I want to pass a very long string to a multilined TextBox. After doing this,
      > I want to resize the TextBox vertically, so that the text fits into the
      > TextBox exactly. Any ideas? I need it for a custom MessageBox.
      >
      > Thank you
      >
      > Rudi
      >
      >
      >[/color]


      Comment

      Working...