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.
Unfortunately, activation email could not send to your email. Please try again.

Change standard context menu for diagram

Thread ID:

Created:

Updated:

Platform:

Replies:

104404 Jul 17,2012 04:50 AM Jul 24,2012 02:41 AM Windows Forms 3
loading
Tags: Diagram
Klaudiusz Bryja
Asked On July 17, 2012 04:50 AM

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

Amsath Ali M [Syncfusion]
Replied On July 20, 2012 03:08 AM

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

Klaudiusz Bryja
Replied On July 20, 2012 07:21 AM

Thank you. It works perfect.

Amsath Ali M [Syncfusion]
Replied On July 24, 2012 02:41 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;