2

i'm constructing a TextBox at runtime:

edit = new TextBox();
this.Controls.Add(edit);
edit.BorderStyle = System.Windows.Forms.BorderStyle.None;

Sometime later i set the location (Location, Left/Top) of the edit box:

edit.Location = new Point(newX, newY);

Problem is that before i adjust the text box's location its Height is 20 px. e.g.:

edit.Height     20

But as soon as i change the Location, the text box's height changes to 13 px, e.g.:

edit.Height     13

The problem, of course, is that my value of newY is based on the height of the text box. As soon as i adjust the text box's location it then shrinks itself - making my calculated value useless.

What i would like is a way to force a TextBox to rethink it's height:

Before

newX = (int)Math.Round(2*scaleFactor.Width);
newY = (containerHeight - edit.Height) / 2;

After

edit.RethinkAutoSize();
newX = (int)Math.Round(2*scaleFactor.Width);
newY = (containerHeight - edit.Height) / 2;

How can i tell a textbox to update it's internal sense of it's "proper" height?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • Was 20 correct? I mean, maybe it should rethink (I love the word) its height earlier. – Gert Arnold Dec 12 '11 at 21:37
  • i stole the term from Borland's equivalent of the .NET Framework, which used `RethinkLines` as a method to update the visibility of a menu separator when nithing's below it. Later i stole it the same term for other such things, where ambient conditions have changed and the object-oriented nature of object wrappers becomes a hindrance, and we have to break encapsulation to make things work. Presumably 20 wasn't correct, since it decided it didn't like it anymore. – Ian Boyd Dec 12 '11 at 21:52
  • I've been rethinking... the only way I see is to (re)set the font of the TextBox. – Gert Arnold Dec 16 '11 at 15:45

0 Answers0