Increasing height of text box

  • Thread starter Thread starter RateTheBuilder
  • Start date Start date
R

RateTheBuilder

Hi

I have a multi-line text box displaying data inside a datagrid. I have the
height set to 50px and the width to 200px. If the data populating the text
box is larger than this, then naturally the scrollbars appear.

What I need is rather than the vertical scroll bar to appear, that the text
box increases in height to contain the text.

Any ideas or pointers to tutorials would be greatly appreciated.

Thanks in advance.

Brendan

______________________________________________
Rate your experiences with your UK and Ireland builders at
http://www.ratethebuilder.co.uk
=========================================
 
Strange requirement? But hey ho.

I dont know if the textboxes have an event for when the scrollbars kick in,
if they do hook that event and on that event firing dont show scroll bars
but increase size.

Assuming that event does not exist you could work out roughly how many
characters it can contain in its initial state and on keyPress store the
length of data in the textbox and do:-

//pseudo code
If length > maxChars
/ /increase size by x pixels
maxChars += numCharsToFitALine;

Something like that should work? Its not sexy code at all but off the top of
my head thats a quick fire solution
 
Hello RateTheBuilder,

You can set the height of your textbox based on the calculation of your text
hight multiply by number of lines

To calc the text size use
this.CreateGraphics().MeasureString(string text, Font font, int width);
or TextRenderer.MeasureText (.net 2.)

but, take into account that the real size of you sign could be more then
calculated, because these methods don't calc glyph size.


R> Hi
R>
R> I have a multi-line text box displaying data inside a datagrid. I
R> have the height set to 50px and the width to 200px. If the data
R> populating the text box is larger than this, then naturally the
R> scrollbars appear.
R>
R> What I need is rather than the vertical scroll bar to appear, that
R> the text box increases in height to contain the text.
R>
R> Any ideas or pointers to tutorials would be greatly appreciated.
R>
R> Thanks in advance.
R>
R> Brendan
R>
R> ______________________________________________
R> Rate your experiences with your UK and Ireland builders at
R> http://www.ratethebuilder.co.uk
R> =========================================
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top