Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to have text size adjust to fill space.
 

How to have text size adjust to fill space.

I have a resizable panel that contains a textbox. The textbox can only display a single character at a time. The textbox's dock is set to fill. How would I adjust the size of the text in the textbox to fill all vertical space available?

So as the panel is increased in size, the size of the text increases to the max possible visible size. And visa versa.

Thanks.

BioGeek  Tuesday, June 13, 2006 7:08 PM

There isn't a property you can set, if that's what you're hoping.

You would have to subscribe to one of the text boxes size events and change the font size to correlate to the size of the text box.For example:

private void textBox1_SizeChanged(object sender, EventArgs e)
{
textBox1.Font = new Font(textBox1.Font.FontFamily, textBox1.Height, GraphicsUnit.Pixel);
}

Peter Ritchie  Tuesday, June 13, 2006 7:56 PM

There isn't a property you can set, if that's what you're hoping.

You would have to subscribe to one of the text boxes size events and change the font size to correlate to the size of the text box.For example:

private void textBox1_SizeChanged(object sender, EventArgs e)
{
textBox1.Font = new Font(textBox1.Font.FontFamily, textBox1.Height, GraphicsUnit.Pixel);
}

Peter Ritchie  Tuesday, June 13, 2006 7:56 PM

Here is what I did:

private void GameCell_Resize(object sender, EventArgs e) {

if (textBox.Text.Length > 0) {

Graphics g = Graphics.FromHwndInternal(this.Handle);

SizeF currentTextSize = g.MeasureString(textBox.Text, textBox.Font);

Size currentWindowSize = this.Size;

float currTextHeight = (int)currentTextSize.Height;

float currWindowHeight = currentWindowSize.Height;

float zoom = currWindowHeight / currTextHeight;

textBox.Font = new Font(textBox.Font.FontFamily,

textBox.Font.Size * zoom, textBox.Font.Style);

}

}

BioGeek  Tuesday, June 13, 2006 7:59 PM

You can use google to search for other answers

Custom Search

More Threads

• MenuItem - drag and drop
• proper implementation of IPersistComponentSettings
• self created icons
• Cannot Open Form2 from BeginInvoke
• 'Resources.Resources' error unable to open form in designer mode
• There is already a command handler for the menu command '5efc7975-14bc-11cf-9b2b-00aa00573819 : 17'
• Create the Drop-Down List of Controls in a Properties Window like VS
• get events of an object declared in code
• Image size in TreeNode
• problems in user controls manipulation