This is a migrated thread and some comments may be shown as answers.

How to add a context menu by pressing a RadButton?

3 Answers 297 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Serg
Top achievements
Rank 1
Veteran
Serg asked on 06 Jan 2021, 12:53 AM

How to add a context menu by pressing a RadButton?

ContextMenuStrip mainMenu = new ContextMenuStrip();
RadButtonElement btn = new RadButtonElement();

3 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Jan 2021, 07:40 AM

Hello, Serg,

Please have a look at the following help article which demonstrates how to create and show a RadContextMenu for a certain control: https://docs.telerik.com/devtools/winforms/controls/menus/contextmenu/add-context-menu-in-code 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Serg
Top achievements
Rank 1
Veteran
answered on 06 Jan 2021, 01:41 PM
Thank you! Another question: can you customize the menu so that it extends to the left of the location point?

ps By default, it exits to the right of the point
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Jan 2021, 09:42 AM

Hello, Serg,   

The RadContextMenu.Show method accepts a parameter specifying the exact location where to show the menu. If you want to show the menu at the left side of the cursor, you just need to adjust the location:  

        RadContextMenu radContextmenu = new RadContextMenu();

        public RadForm1()
        {
            InitializeComponent();

            RadMenuItem menuItem1 = new RadMenuItem();
            menuItem1.Text = "Show";
            radContextmenu.Items.Add(menuItem1);
            RadMenuItem menuItem2 = new RadMenuItem();
            menuItem2.Text = "Hide";
            radContextmenu.Items.Add(menuItem2);
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            var args = e as MouseEventArgs; 

            radContextmenu.Show(this.radButton1, new Point(args.Location.X - radContextmenu.DropDown.Width, args.Location.Y));
        }

        private void RadForm1_Load(object sender, EventArgs e)
        {
            radContextmenu.DropDown.LoadElementTree();
        }

I believe that it would fit your needs.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Serg
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Serg
Top achievements
Rank 1
Veteran
Share this question
or