Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
912
programmatically adjust ultratexteditor width base on contents
posted

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?

Parents
No Data
Reply
  • 469350
    Offline posted

    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;
            }

Children
No Data