Implementing a Custom Telerik RadTextBox Control in a WinForms Application

.NET Core

Introduction

Here is a sample of implementing a custom control inherited from RadTextBox with properties IsEmpty and NotIsEmpty enabled by default for the ShowClearButton property for the text box, the “x” that clears the text box content.

This code works on .NET 5/6/7/8.

using System;
using System.Drawing;
using Telerik.WinControls.UI;

namespace MyControls
{

    public class MyRadTextBox : RadTextBox
    {
        public MyRadTextBox()
        {

        }
        public bool IsEmpty
        {
            get
            {
                return string.IsNullOrEmpty(base.Text);
            }
        }

        public bool IsNotEmpty
        {
            get
            {
                return !string.IsNullOrEmpty(base.Text);
            }
        }

        protected override void OnLoad(Size desiredSize)
        {
            base.OnLoad(desiredSize);
            base.ShowClearButton = true;
            
        }

    }

}

Sample use of property IsEmpty.

     if (this.myRadTextBox1.IsEmpty)
     {
         // Do something
     }

To use in a Form, drag from the Toolbox MyRadTextBox.

You can replace all references for RadTextBox with MyRadTextBox and add the namespace in the global use.

This solution can be done to other controls if you need to override any property or add custom properties.

Have an excellent coding.


Similar Articles