New to Telerik UI for WinForms? Start a free 30-day trial
How to Add Custom ContextMenu for RadTextBox
Updated over 6 months ago
Environment
| Product Version | Product | Author |
|---|---|---|
| 2022.1.222 | RadTextBox for WinForms | Desislava Yordanova |
Description
By default, RadTextBox offers the following context menu after right-clicking the controls:

This is actually the context menu for the hosted TextBox that Microsoft offers.
This article demonstrates a sample approach how to eliminate the default menu and assign your custom one.
Solution
In order to remove the default context menu, it is necessary to set the RadTextBox.TextBoxElement.TextBoxItem.HostedControl.ContextMenuStrip property to a new instance of ContextMenuStrip:
C#
this.radTextBox1.TextBoxElement.TextBoxItem.HostedControl.ContextMenuStrip = new ContextMenuStrip();
However, if you want to achieve your custom items, it is necesary to create your own ContextMenuStrip

C#
public RadForm1()
{
InitializeComponent();
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem copy = new ToolStripMenuItem("Copy", Properties.Resources.copy);
copy.Click += copy_Click;
menu.Items.Add(copy);
ToolStripMenuItem cut = new ToolStripMenuItem("Cut", Properties.Resources.cut);
cut.Click += cut_Click;
menu.Items.Add(cut);
ToolStripMenuItem paste = new ToolStripMenuItem("Paste", Properties.Resources.paste);
paste.Click += paste_Click;
menu.Items.Add(paste);
this.radTextBox1.TextBoxElement.TextBoxItem.HostedControl.ContextMenuStrip = menu;
}
private void paste_Click(object sender, EventArgs e)
{
//TODO paste
}
private void cut_Click(object sender, EventArgs e)
{
//TODO cut
}
private void copy_Click(object sender, EventArgs e)
{
//TODO copy
}