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?
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.
Thanks both for your replies. I'm confused though -- all I'm trying to accomplish is what the built-in .net textbox (System.Windows.Forms.TextBox) already does. When you drag one onto a form, it's Text property is empty.