I adjust the text contents and font size in an ultratexteditor at runtime. What is the best way to resize the width of the control so it exactly fits the current contents?
I think that a better way to achieve this would be to use the auto-sizing functionality of the editor, since that will take into account the borders, editor buttons, and other extra elements that might exist in the UltraTextEditor, in addition to the text. This will also account for differences in text rendering like GDI vs. GDI Plus.
private Size AutoSizeUltraTextEditor(UltraTextEditor ultraTextEditor) { var editElement = ultraTextEditor.UIElement.GetDescendant(typeof(EmbeddableUIElementBase)) as EmbeddableUIElementBase; if (editElement != null) { var editor = editElement.Editor; var idealSize = editElement.Editor.GetSize( editElement.Owner, editElement.OwnerContext, false, true, true ); ultraTextEditor.Width = idealSize.Width; return idealSize; } return Size.Empty; }