I canβt believe that there is still no elegant way. Here is what I puzzled:
textBox.Height += textBox.GetPositionFromCharIndex(textBox.Text.Length - 1).Y + 3 + textBox.Font.Height - textBox.ClientSize.Height;
This works by determining the pixel coordinates of the last character of the text.
You can do this after setting the content, i.e. in the OnLoad of the Form element or OnTextChanged of the TextBox control. If the fixed width changes when the user resizes the form, you should also take care of this, i.e. OnResize or OnClientSizeChanged .
TextBox supports the AutoSize property. However, it is already set to true by default, and it does not appear in the Property Editor or IntelliSense. This is easy to change the font height and does not work when using MultiLine = true :( - this is not mentioned in the documentation .
Other options may include the use of another control, such as RichTextBox or Label . I haven't tried it yet, but Shortcut seems to support AutoSize much better.
maf-soft
source share