Textbox Length

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

    #1

    Textbox Length

    I need to set TextBox length based on the text length in the TextBox, so the
    entire text in the box is visible. Can anyone point me to an info on how to
    accomplish this?

    Thank You


    Peter



  • Truong Hong Thi

    #2
    Re: Textbox Length

    Peter, try something like this:

    using (Graphics g = textBox1.Create Graphics())
    {
    SizeF s = g.MeasureString (textBox1.Text, textBox1.Font);
    textBox1.Size = new Size((int) s.Width, (int) s.Height);
    }

    Hope it helps,
    Thi

    Comment

    • Peter

      #3
      Re: Textbox Length


      "Truong Hong Thi" <thi1981@gmail. com> wrote in message
      news:1139287572 .845371.184620@ f14g2000cwb.goo glegroups.com.. .[color=blue]
      > Peter, try something like this:
      >
      > using (Graphics g = textBox1.Create Graphics())
      > {
      > SizeF s = g.MeasureString (textBox1.Text, textBox1.Font);
      > textBox1.Size = new Size((int) s.Width, (int) s.Height);
      > }
      >
      > Hope it helps,
      > Thi
      >[/color]

      Thank You very much, this works


      Comment

      • Rain County

        #4
        Re: Textbox Length

        That's very helpful and instructive... thanks!


        "Truong Hong Thi" <thi1981@gmail. com> wrote in message
        news:1139287572 .845371.184620@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > Peter, try something like this:
        >
        > using (Graphics g = textBox1.Create Graphics())
        > {
        > SizeF s = g.MeasureString (textBox1.Text, textBox1.Font);
        > textBox1.Size = new Size((int) s.Width, (int) s.Height);
        > }
        >
        > Hope it helps,
        > Thi
        >[/color]


        Comment

        Working...