Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Whatever the aim is.</p> <p>If the size of the textbox should be dynamically set up based on the string, which should be the text inside this box, <strong>there is no nice option</strong>.</p> <p><strong>Reasons :</strong> MeasureString uses usual string formatters as delimiters for its own width and height. Means, carriage return and line feed are parsed, too. Resulting in a sizeF.Width and sizeF.Height.</p> <p>Depending on the string( and its font and number of lines ) these both variables can carry values, which are sometimes useless to be used as width/height values of a textbox ( because <strong>they can be bigger than the parentform's values and this would resize the textbox to a size, with left and bottom borders beyond those of the parent form</strong>).</p> <p>Some solutions are still available, depending on the aim, one would like to achieve.</p> <p>One idea would be : Create a textbox in designer, size = 100 X 100. <strong>enable word-wrapping</strong>.</p> <p>In the <strong>OnTextChanged</strong> event handler of the textbox, we just resize the textbox's width to a value, defined by ourself (e.g. parentform.Width or another hard value ).</p> <p><strong>This would cause the word wrap to recalculate the string in the textbox</strong> and this would rearrange all the characters inside the textbox, because word wrap is enabled.</p> <p>The height of the textbox could can be set hard to parentform.Height, for example.</p> <p>BUT, better : set the height dynamically,based on the Y value of the ReturnValue (Point) of the method texbox.GetPositionFromCharIndex(textbox.TextLength -1 ). Then, with <strong>Math.Min()</strong> determine, which is smaller ( either parentform.Height or Point.Y ) , and reset the textbox size to new Size(previousDeterminedWidth, nowDeterminedHeight).</p> <p>Please keep in mind ( if scrollbars are enabled ) to add about 17 pixs to Your width calculation.</p> <p>Best regards</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload