We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Change standard context menu for diagram

Is it possible to add/remove/cheange options in standard diagram context menu? I want to add some options to Connectors (we will have some predifined connectors). I attach image which show what I want to achive.


contextMenu_d5779a06.zip

3 Replies

AA Amsath Ali M Syncfusion Team July 20, 2012 07:08 AM UTC

Hi Klaudiusz,

 

Thanks for your interest in Syncfusion products.

 

Yes, it is possible to add/remove/change items in the diagram’s default context menu. You can get the items in the default context menu either by its ‘Index’ or through its ‘Text’. Please refer the below code snippet to add/remove items from the default context menu.

 

Here is the code:

[C#]

//Add new item to the context menu.

private void button1_Click(object sender, EventArgs e)

        {

            ToolStripSeparator separator = new ToolStripSeparator();

            CustomNode = new ToolStripMenuItem();

            CustomNode.Text = "CustomNode";

            CustomNode.Click += new EventHandler(CustomNode_Click);

 

            //Adding new item to the default contextMenu

            ToolStripMenuItem shapeItem = cxtMenu.Items[4] as ToolStripMenuItem;

            shapeItem.DropDownItems.Add(separator);

            shapeItem.DropDownItems.Add(CustomNode);

 

        }

//Removes the item “Rectangle” from the context menu.

private void button2_Click(object sender, EventArgs e)

        {

            for (int i = 0; i < diagram1.ContextMenuStrip.Items.Count; i++)

            {

                if (!(diagram1.ContextMenuStrip.Items[i] is ToolStripSeparator))

                {

                    ToolStripMenuItem item = diagram1.ContextMenuStrip.Items[i] as ToolStripMenuItem;

                    if (item.Text == "Rectangle")

                    {

                        diagram1.ContextMenuStrip.Items.Remove(item);

                        break;

                    }

                    else if (item.DropDownItems.Count > 0)

                    {

                        for (int j = 0; j < item.DropDownItems.Count; j++)

                        {

                            if (item.DropDownItems[j].Text == "Rectangle")

                            {

                                item.DropDownItems.RemoveAt(j);

                                break;

                            }

                        }

                    }

                }

            }    

        }

 

Here is the sample:

F104404.zip

 

Please let us know if you have any queries.

 

Regards,

Amsath Ali. M



F104404_35a960f.zip


EN enova July 20, 2012 11:21 AM UTC

Thank you. It works perfect.


AA Amsath Ali M Syncfusion Team July 24, 2012 06:41 AM UTC

Hi Klaudiusz,

 

Thanks for your update.

 

We are happy to hear that the issue has been resolved.

Please let us know if you require any further assistance on this. We would be happy to help you out.

 

Regards,

Amsath Ali. M


Loader.
Live Chat Icon For mobile
Up arrow icon