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
945
UltraTextEditor Undesirable Default Text
posted

When you drag an UltraTextEditor control onto a form, it has a default text value, e.g. 'UltraTextEditor1'.  This is undesirable, because most of the time you don't default the value of text boxes for user input, and when designing forms with many text boxes, you have to clear out the default text on each one which takes a lot of unnecessary time.  I cannot find any way (e.g. through inheritance, etc.) to prevent this behavior.  Is there some way to do it that I just haven't come across?

Parents
  • 9298
    posted

    Rory,

    The Text property is inherited from Control and is set by Visual Studio to the name of the instance of the control.  I have attached a sample where I created a CustomControl that inherits from the UltraTextEditor and contains a "Text" property which prevents the setting of the Text property at design time.  I also added a property to allow the Text property to be set at design time.  You can set this property to "true' after dragging the control onto the Form so that you can set that Text property if you want to. 

    Open the attached application in Visual Studio 2010 and drag the CustomTextEditor from the Toolbox on to the Form.  You should see that the control does not have any text in it. 

    If you don't want to add this "AllowDesignTimeText" property then the designer will need to be changed.  This can be done but it is rather cumbersome.  Take a look at the code below:

        [Designer("WindowsFormsApplication2.TextEditorDesigner")]
        public class TextEditor : UltraTextEditor
        {
        }
        public class TextEditorDesigner : UltraTextEditorDesigner
        {
            public override void InitializeNewComponent(IDictionary defaultValues)
            {
                base.InitializeNewComponent(defaultValues);
                ISite site = base.Component.Site;
                if (site != null)
                {
                    PropertyDescriptor descriptor = TypeDescriptor.GetProperties(base.Component)["Text"];
                    if (((descriptor != null) && (descriptor.PropertyType == typeof(string))) && (!descriptor.IsReadOnly && descriptor.IsBrowsable))
                    {
                        descriptor.SetValue(base.Component, String.Empty);
                    }
                }
            }
        }

    The designer will need to be in a different assembly because it requires a reference to Infragistics2.Win.v12.1.Design and System.Design. 

    Infragistics2.Win.v12.1.Design cannot be distributed.

    System.Design is not part of the .NET Framework Client profile.

    The Designer attribute may need to be modified to use one that also specifies the assembly.

    I hope this is helpful.

    CustomTextEditorDemo.zip
Reply Children