Auto Expand Textbox

T

Thom Little

Is there a textbox control to which I can pass a string of an arbitrary
length and it will automatically expand to allow all characters to be
displayed?

I need to have a fixed width and allow the control to add add"lines" with
the wrapped text if needed.
 
C

Chris Dunaway

Thom said:
Is there a textbox control to which I can pass a string of an arbitrary
length and it will automatically expand to allow all characters to be
displayed?

I need to have a fixed width and allow the control to add add"lines" with
the wrapped text if needed.

If you set the textbox MultiLine property to true, then adding lines to
the Lines property should do what you wish.
 
J

Jeff Gaines

Is there a textbox control to which I can pass a string of an arbitrary
length and it will automatically expand to allow all characters to be
displayed?

I need to have a fixed width and allow the control to add add"lines" with
the wrapped text if needed.

If you get the Graphics property of the Text Box you can measure your
string and calculate how high the Text Box needs to be, something like:

Graphics gfx = txtPath.CreateGraphics();
string strText = "";
SizeF sf = gfx.MeasureString(strText, txtPath.Font);
int intHeight = (int)(sf.Width / txtPath.Width);
txtPath.Height = intHeight;
gfx.Dispose();

strText would contain the string you want to put in the Text Box - and you
need to check my maths!
 
J

Jeff Gaines

If you get the Graphics property of the Text Box you can measure your
string and calculate how high the Text Box needs to be, something like:

Graphics gfx = txtPath.CreateGraphics();
string strText = "";
SizeF sf = gfx.MeasureString(strText, txtPath.Font);
int intHeight = (int)(sf.Width / txtPath.Width);
txtPath.Height = intHeight;
gfx.Dispose();

strText would contain the string you want to put in the Text Box - and you
need to check my maths!

Sorry, the height calculation should be:
txtPath.Height = (int)(intHeight * sf.Height);
 

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

Top