views:

142

answers:

4

I don't find a CanGrow property on the Textbox control. This is common in some other controls, and what it does is expand the control to acomodate more data. Anyway to get this feature in the TextBox?

A: 

I'm not familiar with CanGrow. Are you looking for Anchor property perhaps?

Judah Himango
A: 

Anyway to get this feature in the TextBox?

Well, yes, but, you may need to look into doing this manually. The Graphic.MeasureString() function may be what you are looking for in order to set the width properly.

Keep in mind that MeasureSting may have issues measuring multiline strings.

John Gietzen
A: 

If you set the anchor properties to top,left,bottom,right then the control will grow as the form resizes.

I think a better option is to use docking though. I usually set up a panel layout with one docked to client, then I put the control I want resized in the panel docked to client, and set the control to dock to client as well.

Jeremy
only good if I want to fill the whole form. I don't. But If I have a very long line I want it to wrap and expand the textbox.
bochur1
A: 

Well, I came up with this:

Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox.TextChanged
     'check to see if textbox has text
     If (TextBox.TextLength > 0) Then
      'resize height of textbox by count of lines (plus add some padding)
      TextBox.ClientSize = New Size(TextBox.ClientSize.Width, Convert.ToInt32((TextBox.Lines.Length * TextBox.Font.Height) + (TextBox.Font.Height * 0.5)))
     Else
      'resize to one line height (plus padding)
      TextBox.ClientSize = New Size(TextBox.ClientSize.Width, Convert.ToInt32(TextBox.Font.Height + (TextBox.Font.Height * 0.5)))
     End If
End Sub

Note: it doesn't work with word-warp.

DanStory