New to Telerik UI for WinFormsStart a free 30-day trial

Notification Button

Updated on Sep 15, 2025
Product VersionProductAuthorLast modified
Q2 2015RadButton for WinFormsDesislava YordanovaNovember 05, 2015

Problem

This article demonstrates how to create a notification button.

NotificationButton001

Solution

Firstly, you should create a new project with a RadRibbonForm. Afterwards, drag several RadButton controls from the Toolbox and drop them onto the form. You need to insert a RibbonTab and a RadRibbonBarGroup with several RadButtonElements. The following screenshot illustrates how the design time should look like:

NotificationButton002

Next, we should create a derivative of RadButton where the CreateChildItems method should be overridden in order to add a red circled LightVisualElement to illustrate the notification. The NotificationCount property controls whether the notification badge will be visible. If its value is set to 0, the red circle will be hidden:

C#
public class NotificationButton : RadButton
{
    int result;
    LightVisualElement lve;
    int sizeConst = 26;

    protected override void CreateChildItems(Telerik.WinControls.RadElement parent)
    {
        base.CreateChildItems(parent);

        lve = new LightVisualElement();
        lve.BackColor = Color.Red;
        lve.DrawFill = true;
        lve.StretchHorizontally = false;
        lve.StretchVertically = false;
        lve.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        lve.Shape = new RoundRectShape(sizeConst / 2);
        lve.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        lve.ForeColor = Color.White;
        lve.MinSize = new Size(sizeConst, sizeConst);
        lve.Visibility = ElementVisibility.Collapsed;
        this.RootElement.Children.Add(lve);

        // Pushing the ButtonElement off the top and right edges
        // so that the badge is not completely overlapped with the button
        this.ButtonElement.Margin = new System.Windows.Forms.Padding(0, 5, 5, 0);
    }

    protected override void InitLayout()
    {
        base.InitLayout();

        lve.Margin = new System.Windows.Forms.Padding(this.Size.Width - sizeConst - 1, 0, 0, 0);
    }

    protected override void OnSizeChanged(EventArgs e)
    {
        base.OnSizeChanged(e);

        lve.Margin = new System.Windows.Forms.Padding(this.Size.Width - sizeConst - 1, 0, 0, 0);
    }

    [DefaultValue(0)]
    public int NotificationCount
    {
        get
        {
            if (lve.Text != null)
            {
                bool isInt = int.TryParse(lve.Text, out result);
                if (isInt)
                {
                    return result;
                }
            }

            return 0;
        }
        set
        {
            if (value > 0)
            {
                lve.Visibility = ElementVisibility.Visible;
            }
            else
            {
                lve.Visibility = ElementVisibility.Collapsed;
            }
            lve.Text = value.ToString();
        }
    }

    protected override Size DefaultSize
    {
        get
        {
            return new Size(150, 50);
        }
    }
}

The complete examples in C# and VB can be downloaded by clicking the following link.

In this article
ProblemSolution
Not finding the help you need?
Contact Support