To reproduce: add a RadMaskedEditBox and use the following code: Sub New() InitializeComponent() Me.RadMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Numeric Me.RadMaskedEditBox1.Mask = "N1" Dim item As Item = New Item(Nothing, "Item1") RadMaskedEditBox1.DataBindings.Add("Value", item, "StockTypeId", True, DataSourceUpdateMode.OnPropertyChanged) End Sub Public Class Item Private _stockId As Nullable(Of Integer) Public Sub New(value As Nullable(Of Integer), name As String) Me._stockId = value End Sub Public Property StockTypeId() As Nullable(Of Integer) Get Return _stockId End Get Set(ByVal value As Nullable(Of Integer)) _stockId = value Console.WriteLine(value) End Set End Property End Class The user is not allowed to enter a new numeric value. Wokraround: Public Class CustomNumericCharacterTextBoxProvider Inherits NumericCharacterTextBoxProvider Private owner As RadMaskedEditBoxElement Public Sub New(mask As String, culture As CultureInfo, numericType As NumericCharacterTextBoxProvider.RadNumericMaskFormatType, _ owner As RadMaskedEditBoxElement) MyBase.New(mask, culture, numericType, owner) Me.owner = owner End Sub Protected Overrides Function AllowAppendCharacters() As Boolean If owner.Text = "" AndAlso owner.Mask = "N1" Then Return True End If Return MyBase.AllowAppendCharacters() End Function End Class Public Class CustomMaskedEditBox Inherits RadMaskedEditBox Public Overrides Property ThemeClassName As String Get Return GetType(RadMaskedEditBox).FullName End Get Set(value As String) MyBase.ThemeClassName = value End Set End Property Public Sub New() MyBase.New() Me.MaskType = Telerik.WinControls.UI.MaskType.Numeric Me.Mask = "N1" Dim numericMaskProvider As NumericMaskTextBoxProvider = Me.MaskedEditBoxElement.Provider Dim fi As FieldInfo = GetType(NumericMaskTextBoxProvider).GetField("provider", BindingFlags.Instance Or BindingFlags.NonPublic) fi.SetValue(numericMaskProvider, _ New CustomNumericCharacterTextBoxProvider(numericMaskProvider.Mask, numericMaskProvider.Culture, _ NumericMaskTextBoxProvider.GetFormat(numericMaskProvider.Mask, numericMaskProvider.Culture), _ Me.MaskedEditBoxElement)) End Sub End Class
To reproduce: - Set the provider to FreeFormDateTimeProvider - Bind the control to a value. - Clear the date and tab out of the control. Workaround: Seth the value in the ParsingDateTime event handler: if (e.InputString == "") { this.SetToNullValue(); }
Description: When binding to a null value, the RadSpinEditor throws an exception. This missing functionality is also noticed with the standard Windows Numeric Up Down control. How to reproduce: - add a RadSpinEditor and two RadButtons; - use the following code: public partial class Form1 : Form { private BindingSource _bindActiveObject = new BindingSource { DataSource = typeof(MyBindingObject) }; public Form1() { InitializeComponent(); this.radSpinEditor1.DataBindings.Add(new Binding("Value", _bindActiveObject, "MyValue")); } private void radButton1_Click(object sender, EventArgs e) { _bindActiveObject.DataSource = new MyBindingObject { MyValue = Convert.ToDouble(100) }; } private void radButton2_Click(object sender, EventArgs e) { _bindActiveObject.DataSource = new MyBindingObject { MyValue = null }; } } public class MyBindingObject { private decimal? _myValue; public decimal? MyValue { get { return _myValue; } set { _myValue = value; } } } Workaround: Use the following custom RadSpinEditor: private BindingSource _bindActiveObject = new BindingSource { DataSource = typeof(MyBindingObject) }; public Form1() { InitializeComponent(); this.radSpinEditor1.NullableValueChanged += Form1_NullableValueChanged; this.radSpinEditor1.DecimalPlaces = 2; this.radSpinEditor1.DataBindings.Add(new Binding("NullableValue", _bindActiveObject, "MyValue", true, DataSourceUpdateMode.OnPropertyChanged)); } private void Form1_NullableValueChanged(object sender, EventArgs e) { Console.WriteLine("NullableValue = " + this.radSpinEditor1.NullableValue + ""); } private void radButton1_Click(object sender, EventArgs e) { MyBindingObject obj = new MyBindingObject { MyValue = 65.45m }; _bindActiveObject.DataSource = obj; } private void radButton2_Click(object sender, EventArgs e) { _bindActiveObject.DataSource = new MyBindingObject { MyValue = null }; } public class MyBindingObject { private decimal? _myValue; public decimal? MyValue { get { return _myValue; } set { _myValue = value; } } } public class MySpinEditor : RadSpinEditor { public event EventHandler NullableValueChanged; public decimal? NullableValue { get { return (this.SpinElement as MySpinEditorElement).NullableValue; } set { (this.SpinElement as MySpinEditorElement).NullableValue = value; } } public MySpinEditor() { this.AutoSize = true; this.TabStop = false; base.SetStyle(ControlStyles.Selectable, true); } protected override void CreateChildItems(RadElement parent) { Type baseType = typeof(RadSpinEditor); MySpinEditorElement element = new MySpinEditorElement(); element.RightToLeft = this.RightToLeft == System.Windows.Forms.RightToLeft.Yes; this.RootElement.Children.Add(element); element.ValueChanging += spinElement_ValueChanging; element.ValueChanged += spinElement_ValueChanged; element.TextChanging += spinElement_TextChanging; element.NullableValueChanged += element_NullableValueChanged; element.KeyDown += OnSpinElementKeyDown; element.KeyPress += OnSpinElementKeyPress; element.KeyUp += OnSpinElementKeyUp; baseType.GetField("spinElement", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, element); } void element_NullableValueChanged(object sender, EventArgs e) { if (this.NullableValueChanged != null) { this.NullableValueChanged(this, EventArgs.Empty); } } private Dictionary<string, MethodInfo> cache = new Dictionary<string, MethodInfo>(); private void InvokeBaseMethod(string name, params object[] parameters) { if (!cache.ContainsKey(name)) { cache[name] = typeof(RadSpinEditor).GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic); } cache[name].Invoke(this, parameters); } private void OnSpinElementKeyUp(object sender, KeyEventArgs e) { this.InvokeBaseMethod("OnSpinElementKeyUp", sender, e); } private void OnSpinElementKeyPress(object sender, KeyPressEventArgs e) { this.InvokeBaseMethod("OnSpinElementKeyPress", sender, e); } private void OnSpinElementKeyDown(object sender, KeyEventArgs e) { this.InvokeBaseMethod("OnSpinElementKeyDown", sender, e); } private void spinElement_TextChanging(object sender, TextChangingEventArgs e) { this.InvokeBaseMethod("spinElement_TextChanging", sender, e); } private void spinElement_ValueChanged(object sender, EventArgs e) { this.InvokeBaseMethod("spinElement_ValueChanged", sender, e); this.NullableValue = this.Value; } private void spinElement_ValueChanging(object sender, ValueChangingEventArgs e) { this.InvokeBaseMethod("spinElement_ValueChanging", sender, e); } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Tab) { (this.SpinElement as MySpinEditorElement).CommitText(); } else if (keyData== Keys.Delete) { (this.SpinElement as MySpinEditorElement).NullableValue = null; } return base.ProcessCmdKey(ref msg, keyData); } protected override Size DefaultSize { get { return GetDpiScaledSize(new Size(100, 20)); } } } public class MySpinEditorElement : RadSpinElement { private bool validating; private decimal? nullableValue; private RadButtonElement nullButton; public decimal? NullableValue { get { return this.nullableValue; } set { this.nullableValue = value; if (value.HasValue) { this.internalValue = value.Value; } else { this.internalValue = 0m; } this.Validate(); this.OnNullableValueChanged(); } } protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.CommitText(); e.Handled = true; return; } base.OnKeyDown(e); } void nullButton_Click(object sender, EventArgs e) { this.NullableValue = null; } public virtual void CommitText() { this.NullableValue = this.GetValueFromText(); } protected override decimal GetValueFromText() { if (this.TextBoxItem.Text == "") { return 0m; } return base.GetValueFromText(); } public override bool Validate() { if (!this.NullableValue.HasValue) { this.TextBoxItem.Text = ""; return true; } this.TextBoxItem.Text = this.GetTextFromNumber(this.NullableValue.HasValue ? this.internalValue : 0m, this.Hexadecimal, this.ThousandsSeparator, this.DecimalPlaces); return true; } private string GetTextFromNumber(decimal num, bool hex, bool thousands, int decimalPlaces) { if (hex) { return string.Format("{0:X}", (long)num); } return num.ToString((thousands ? "N" : "F") + decimalPlaces.ToString(CultureInfo.CurrentCulture), CultureInfo.CurrentCulture); } public override void PerformStep(decimal step) { decimal value = this.GetValueFromText(); try { decimal incValue = value + step; value = incValue; } catch (OverflowException) { } this.NullableValue = this.Constrain(value); this.Validate(); } protected override Type ThemeEffectiveType { get { return typeof(RadSpinElement); } } public event EventHandler NullableValueChanged; protected virtual void OnNullableValueChanged() { if (this.NullableValueChanged != null) { this.NullableValueChanged(this, EventArgs.Empty); } } }
To reproduce: please refer to the attached gif file. The error is applicable for all controls that use RadColorDialog while editing, e.g. RadGridView, RadPropertyGrid. Workaround: disable the spineditors: private void RadPropertyGrid1_EditorInitialized(object sender, Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs e) { PropertyGridColorEditor colorEditor = e.Editor as PropertyGridColorEditor; if (colorEditor !=null) { RadColorBoxElement el = colorEditor.EditorElement as RadColorBoxElement; ((RadForm)el.ColorDialog.ColorDialogForm).Load += ColorDialogForm_Load1; } } private void ColorDialogForm_Load1(object sender, EventArgs e) { RadColorDialogForm form = sender as RadColorDialogForm; RadPageView pageView = form.RadColorSelector.Controls["radPageView1"] as RadPageView; Telerik.WinControls.UI.RadColorPicker.ProfessionalColors professionalColors = pageView.Pages[3].Controls["professionalColorsControl"] as Telerik.WinControls.UI.RadColorPicker.ProfessionalColors; foreach (Control c in professionalColors.Controls ) { RadSpinEditor spinEditor = c as RadSpinEditor; if (spinEditor!=null) { spinEditor.SpinElement.TextBoxItem.Enabled = false; } } }
Steps to reproduce: public Form1() { InitializeComponent(); this.Text = Telerik.WinControls.VersionNumber.Number; this.radMaskedEditBox1.Culture = new System.Globalization.CultureInfo("nl-BE"); this.radMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Numeric; this.radMaskedEditBox1.Mask = "C"; this.radMaskedEditBox1.Value = 570.00; } private void radButton2_Click(object sender, EventArgs e) { this.radMaskedEditBox1.Culture = new System.Globalization.CultureInfo("en-US"); } private void radButton1_Click(object sender, EventArgs e) { this.radMaskedEditBox1.Culture = new System.Globalization.CultureInfo("nl-BE"); } Run the application and change the culture between Dutch and English, you will see that the value is reset instead keep it. Workaround: CultureInfo providerDutch = new CultureInfo("nl-BE"); CultureInfo providerEnglish = new CultureInfo("en-US"); public Form1() { InitializeComponent(); this.Text = Telerik.WinControls.VersionNumber.Number; this.radMaskedEditBox1.Culture = providerDutch; this.radMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Numeric; this.radMaskedEditBox1.Mask = "C"; this.radMaskedEditBox1.Value = 570.00; } private void radButton1_Click(object sender, EventArgs e) { double tempValue = double.Parse(this.radMaskedEditBox1.Value.ToString(), NumberStyles.Currency | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, providerEnglish); this.radMaskedEditBox1.Culture = new System.Globalization.CultureInfo("nl-BE"); this.radMaskedEditBox1.Value = tempValue; } private void radButton2_Click(object sender, EventArgs e) { double tempValue = double.Parse(this.radMaskedEditBox1.Value.ToString(), NumberStyles.Currency | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, providerDutch); this.radMaskedEditBox1.Culture = new System.Globalization.CultureInfo("en-US"); this.radMaskedEditBox1.Value = tempValue; }
When NumberFormat.NumberDecimalSeparator is same with NumberFormat.CurrencyGroupSeparator numbers cannot be edited and deleted. As a workaround set these separators to different values.
How to reproduce: Check also the attached video public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radButton1_Click(object sender, EventArgs e) { this.radAutoCompleteBox1.AutoCompleteItems.Clear(); List<RadListDataItem> autoCompleteEntries = new List<RadListDataItem>(); for (int i = 0; i < 10000; i++) { autoCompleteEntries.Add(new RadListDataItem("Joe Smith", "joe@fakecompany.com")); autoCompleteEntries.Add(new RadListDataItem("Adam Petersen", "adam@qwerty.com")); autoCompleteEntries.Add(new RadListDataItem("Jack Russel", "jack@russel.nocom")); autoCompleteEntries.Add(new RadListDataItem("Daniel Finger", "daniel.pinger@gmail.com")); autoCompleteEntries.Add(new RadListDataItem("Richard Vail", "rvail@richardvail.com")); autoCompleteEntries.Add(new RadListDataItem("Sebastian Jonnson", "s.jonnson@sjonnson.com")); autoCompleteEntries.Add(new RadListDataItem("Lee Cooper", "lee.cooper@coopercoorp.com")); autoCompleteEntries.Add(new RadListDataItem("Kelvin Clain", "kclain@clainkevin.com")); autoCompleteEntries.Add(new RadListDataItem("Maria Jenson", "mjenson@mariajenson.com")); autoCompleteEntries.Add(new RadListDataItem("Chelsea Maarten", "chelsea@maarten.com")); } this.radAutoCompleteBox1.AutoCompleteItems.AddRange(autoCompleteEntries); } } Workaround: use Begin/End update block and reset the private patternText field: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radButton1_Click(object sender, EventArgs e) { typeof(RadTextBoxListElement).GetField("patternText", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this.radAutoCompleteBox1.ListElement, null); this.radAutoCompleteBox1.AutoCompleteItems.Clear(); List<RadListDataItem> autoCompleteEntries = new List<RadListDataItem>(); for (int i = 0; i < 10000; i++) { autoCompleteEntries.Add(new RadListDataItem("Joe Smith", "joe@fakecompany.com")); autoCompleteEntries.Add(new RadListDataItem("Adam Petersen", "adam@qwerty.com")); autoCompleteEntries.Add(new RadListDataItem("Jack Russel", "jack@russel.nocom")); autoCompleteEntries.Add(new RadListDataItem("Daniel Finger", "daniel.pinger@gmail.com")); autoCompleteEntries.Add(new RadListDataItem("Richard Vail", "rvail@richardvail.com")); autoCompleteEntries.Add(new RadListDataItem("Sebastian Jonnson", "s.jonnson@sjonnson.com")); autoCompleteEntries.Add(new RadListDataItem("Lee Cooper", "lee.cooper@coopercoorp.com")); autoCompleteEntries.Add(new RadListDataItem("Kelvin Clain", "kclain@clainkevin.com")); autoCompleteEntries.Add(new RadListDataItem("Maria Jenson", "mjenson@mariajenson.com")); autoCompleteEntries.Add(new RadListDataItem("Chelsea Maarten", "chelsea@maarten.com")); } this.radAutoCompleteBox1.ListElement.DataLayer.ListSource.BeginUpdate(); this.radAutoCompleteBox1.AutoCompleteItems.AddRange(autoCompleteEntries); this.radAutoCompleteBox1.ListElement.DataLayer.ListSource.EndUpdate(); } }
Workaround: this.radTextBox1.TextBoxElement.Fill.BackColor = backColor; this.radTextBox1.TextBoxElement.BackColor = backColor;
To reproduce: 1. Add a RadForm and a RadTimePicker/RadDateTimePicker. 2. Change the Enabled property of the RadTimePicker/RadDateTimePicker to false at design time. 3. Apply the Office2013Light theme to the RadTimePicker/RadDateTimePicker at design time. 4. Apply the same theme to the RadForm at design time. If you run the application, you will notice that RadTimePicker/RadDateTimePicker has a gray back color. However, if you turn on/off the Enabled property in a button's Click event, the back color is not gray. Workaround: set the Enabled property to false in the Load event.
Workaround: install .NET Framework 2.0 SP1
Please refer to the attached gif file demonstrating how to reproduce the problem. Workaround: close the popup when pressing Backspace: this.radTextBox1.TextBoxElement.TextBoxItem.TextBoxControl.KeyDown+=TextBoxControl_KeyDown; private void TextBoxControl_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData== Keys.Back) { TextBoxSpellChecker textBoxSpellChecker = _radSpellChecker.GetControlSpellChecker(typeof(RadTextBox)) as TextBoxSpellChecker; if (textBoxSpellChecker!=null) { textBoxSpellChecker.DropDownMenu.ClosePopup(RadPopupCloseReason.Keyboard); } } }
To reproduce: - Use the SpellCheck as you type functionality with RadTextBox. - The "Ignore All" and "Add To Dictionary" strings in the context menu are not changed. Workaround: public RadForm1() { InitializeComponent(); radSpellChecker1.AutoSpellCheckControl = radTextBox1; TextBoxSpellChecker textBoxControlSpellChecker = this.radSpellChecker1.GetControlSpellChecker(typeof(RadTextBox)) as TextBoxSpellChecker; textBoxControlSpellChecker.DropDownMenu.DropDownOpened += DropDownMenu_DropDownOpened; } private void DropDownMenu_DropDownOpened(object sender, EventArgs e) { var menu = (RadDropDownMenu)sender; foreach (var item in menu.Items) { if (item.Text == "Add To Dictionary") { item.Text = "test"; } if (item.Text == "Ignore All") { item.Text = "test"; } } }
To reproduce: public Form1() { InitializeComponent(); this.radTextBox1.Multiline = true; this.radTextBox1.Size = new Size(200, 200); this.radTextBox1.TextChanged += radTextBox1_TextChanged; } private void radTextBox1_TextChanged(object sender, EventArgs e) { this.radTextBox1.BackColor = Color.Red; } Note: when you keep pressed a specific key, you will notice that the memory consumption is increased, although if you force the GarbageCollector, it is released. It is also noticeable that there is text lagging while typing. Please refer to the attached gif file. Workaround: this.radTextBox1.TextBoxElement.TextBoxItem.TextBoxControl.BackColor = Color.Red;
RadMaskedEditBox is not able to edit the value when MaskType is set to Numeric, Mask to percentage and CultureInfo NumberFormat CurrencyGroupSeparator is set to "." Workaround: CultureInfo ci = new CultureInfo(Thread.CurrentThread.CurrentCulture.LCID, false); //do not use user settings Thread.CurrentThread.CurrentCulture = ci;
After binding a boolean property to RadDateTimePicker:Checked, changes made in the property reflect in the GUI, but changes made in the GUI even after lost focus are not reflected on the boolean property. The same test was done with winforms DateTimePicker and the expected behaviour was observed(not the situation reported). above). For further testing background, the class wich contains the binded boolean, implements INotifyPropertyChanged.
To reproduce: Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-CO"); radMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Numeric; radMaskedEditBox1.Mask = "C2"; radMaskedEditBox1.Culture = new System.Globalization.CultureInfo("es-CO"); Click in the masked edit box and press the decimal separator key in the num pad, the cursor is not moved to the desired position. Workaoround: private void RadMaskedEditBox1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyValue == 46) { var textBoxItem = this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem; int indexOfDecimalSeparator = this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.Text.ToLower().IndexOf(','); if (indexOfDecimalSeparator + 1 <= textBoxItem.Text.Length) { textBoxItem.SelectionStart = indexOfDecimalSeparator + 1; } else { textBoxItem.SelectionStart = indexOfDecimalSeparator; } e.Handled = true; } }
Workaround: 1) set the CurrencyNegativePattern to 1 Alternatively: 2) check if the the formatted text is surrounded with brackets and if yes set the value of the masked edit box to be negative
To reproduce: this.radDateTimePicker1.Format = DateTimePickerFormat.Short; this.radDateTimePicker1.Value = new DateTime(2016, 5, 12); this.radTextBox1.Text = "9/5/2016"; Second scenario: this.radDateTimePicker1.Format = DateTimePickerFormat.Short; If you copy "1/7/16" and paste it into RadDateTimeicker, the result date will be "1/7/1616". In the previous version, the result was correct 1/7/2016. Copy the value in the text box and paste it in RadDateTimePicker. Workaround: public Form1() { InitializeComponent(); this.radDateTimePicker1.Format = DateTimePickerFormat.Short; this.radDateTimePicker1.Value = new DateTime(2016, 5, 12); this.radTextBox1.Text = "9/5/2016"; this.radDateTimePicker1.ValueChanging += radDateTimePicker1_ValueChanging; this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.TextBoxItem.TextBoxControl.KeyPress += TextBoxControl_KeyPress; } string clipboardData; private void TextBoxControl_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '\x16') { if (clipboardData != null) { this.radDateTimePicker1.Text = clipboardData; clipboardData = null; } } } private void radDateTimePicker1_ValueChanging(object sender, Telerik.WinControls.UI.ValueChangingEventArgs e) { if (clipboardData == null) { clipboardData = RadMaskedEditBoxElement.GetClipboardText(); } }
To reproduce: public Form1() { InitializeComponent(); this.radDateTimePicker1.Culture = new System.Globalization.CultureInfo("en-GB"); RadTimePickerLocalizationProvider.CurrentProvider = new MyTimePickerLocalizationProvider(); this.radDateTimePicker1.DateTimePickerElement.ShowTimePicker = true; } class MyTimePickerLocalizationProvider : RadTimePickerLocalizationProvider { public override string GetLocalizedString(string id) { switch (id) { case RadTimePickerStringId.HourHeaderText: return "TEST Hours"; case RadTimePickerStringId.MinutesHeaderText: return "TEST Minutes"; case RadTimePickerStringId.CloseButtonText: return "TEST CLOSE"; default: return string.Empty; } } } Workaround: RadDateTimePickerCalendar calendarBehaviorFrom = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar; calendarBehaviorFrom.Calendar.ShowFooter = true; calendarBehaviorFrom.PopupControl.Opened += PopupControl_PopupOpened; private void PopupControl_PopupOpened(object sender, EventArgs args) { RadDateTimePickerDropDown dd = sender as RadDateTimePickerDropDown; TimePickerDoneButtonContent buttonContent = ((RadPanel)dd.HostedControl).Controls[2] as TimePickerDoneButtonContent; var doneButton = ((Telerik.WinControls.UI.TimePickerDoneButtonElement)(buttonContent.RootElement.Children[0])); doneButton.ButtonElement.Text = RadTimePickerLocalizationProvider.CurrentProvider.GetLocalizedString(RadTimePickerStringId.CloseButtonText); }
To reproduce: Using the below code, type something in the text box and execute the button shortcut => the caret remains where it was protected override void OnLoad(EventArgs e) { base.OnLoad(e); AddTextBoxControl(); radButton1.ButtonElement.Shortcuts.Add(new RadShortcut(Keys.Alt, new Keys[] { Keys.R })); } private void radButton1_Click(object sender, EventArgs e) { radTextBoxControl1.Text = ""; } Workaround: Instead of setting the Text to empty string, use the control Clear method.