views:

183

answers:

1

I have a richtextarea with a bunch of text in it. I would like to somehow make it expand to fit all the text without showing scroll bars. I would like the width to stay standard and the height to expand. Is there a good way of doing this? I planned on looping through and adding a pixel to its height every time.. and then checking if the scroll bars are visible. There is no simple way of doing this in vb.net that I can find without using windows api specific methods.

A: 

The way I would do this is by considering the SelectionStart property. If SelectionStart is x or a multiple of x then I would increase my height.

textBox.Multiline = true;
private void textBox_TextChanged(object sender, EventArgs e)
        {
            if (textBox.SelectionStart % 20 == 0)
            {
                textBox.Height += 20;
            }
        }
P.K
This code pretty much says if the index of the currently selected text is an exact multiple of 20 (characters) then make the RichTextBox 20 pixels higher. That does not sound like a terribly stable solution.
Eric J.
20 can be replaced by a number which majestiq decides. But, the essential idea of the answer is to make majestiq understand how this can be done.
P.K