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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do you add a symbol from the palette via code

Thread ID:

Created:

Updated:

Platform:

Replies:

74657 Jun 24,2008 08:47 AM UTC Jul 3,2008 12:45 PM UTC WinForms 7
loading
Tags: Diagram
Peter Mcintosh
Asked On June 24, 2008 08:47 AM UTC

Please can you tell me how to add a symbol from the palette via code.

Ultimately, i want to populate a context menu (via right click mouse button) with each of the items from the palette and allow the user to add nodes from this.

The Help contains the following which i guess must be out of date:


[C#]

//New InsertNodesCmd
InsertNodesCmd insCmd = new InsertNodesCmd();

//Select the Symbol from the PaletteGroupView
this.paletteGroupView1.SelectSymbolModel(this.paletteGroupView1.GroupViewItems[1].Text);
SymbolModel symModel = this.paletteGroupView1.SelectedSymbolModel;

//New NodeCollection
NodeCollection nodes = new NodeCollection();

//Add Symbol to the NodeCollection
if (symModel != null)
{
Symbol triangle = symModel.CreateSymbol();
nodes.Add(triangle);

}
insCmd.Nodes.Concat(nodes);
insCmd.Location = new PointF(125,125);
//ExecuteCommand to add the Symbol
this.diagram1.Controller.ExecuteCommand(insCmd);


J.Nagarajan [Syncfusion]
Replied On June 24, 2008 12:44 PM UTC

Hi ,

Thanks for your interest in Syncfusion products.

Please refer to the attached sample that demonstrates to load the nodes from the palette in v6.2. This sample also illustrates to show the context menu on the selected nodes in PaletteGroupViewItems. When you click on "Add new item", you can add a node in the symbol palette.

http://websamples.syncfusion.com/samples/Diagram.Windows/F74657/main.htm

Please refer to it and let me know if this helps.

Thanks,
Nagaraj


Peter Mcintosh
Replied On June 25, 2008 03:52 PM UTC

Thanks for the reply. I am not sure if this is what I am looking for. I cannot test your solution as I only have the v6.3 libraries. Please can you include the required dll's in the source. Thanks again.


Justin Kim
Replied On June 26, 2008 02:10 AM UTC

I have a similar issue. I have downloaded the sample you provided (which didn't compile with 6.2 libraries for some reason - missing PageScale class?) and it helped, but I still have outstanding questions:

In the previous version of our product, using Syncfusion 4.4, we provided a way for the users to create pre-defined symbols to the diagram through tool bar buttons. This was done through InsertSymbolTool, and bypassed the PalletGroupView (which is deemed too 'heavy' for our application. It takes a large space on screen and we'd like to avoid having to introduce a whole new UI element)

In the 6.2 version, however, I see no InsertSymbol tool or similar. Can you shed some light on this issue?

Thanks



J.Nagarajan [Syncfusion]
Replied On June 26, 2008 12:19 PM UTC

Hi Justin ,

InsertNodeTool is removed in v6.2. However you can work around this problem. You have to create custom node and handle MouseUp event of the diagram control. In the MouseUp event you can insert the custom node into the model. Please refer to the attached sample for more detials.

http://websamples.syncfusion.com/samples/Diagram.Windows/F74657_July26/main.htm

In this sample when you click on Insert->InsertNode menuitem and mouse up the diagram control, the custom node will be inserted.

Please let me know if this helps.

Regards,
Nagaraj


Administrator [Syncfusion]
Replied On June 26, 2008 12:55 PM UTC

Hi Mcinp ,

Please refer to the modified sample that works fine in v6.3.0.6.

http://www.syncfusion.com/Product/uploads/Diagram_Palette_bc11d8ba.zip

This sample illustrates to show the context menu on the selected nodes in PaletteGroupViewItems. When you click on "Add new item", you can add a node in the symbol palette.

Please let me know if this helps.

Regards,
Nagaraj


Peter Mcintosh
Replied On June 30, 2008 10:07 AM UTC

Thank Nagaraj. However, that was not what i was looking for. I was wanting to populate the diagrams context menu with each of the palette items so as i could add items to the diagram from the context menu.

The help (which was included in v6.3) stated that i could use "InsertNodesCmd" class as well as method "this.diagram1.Controller.ExecuteCommand()". I assume this is out of date?

I managed to get a working example by looping through each of the palettes:

//Iterate through the palettes and add menu items for each node found.
foreach (GroupBarItem item in this.symbolPaletteGroupBar.GroupBarItems) {
if (item.Client is PaletteGroupView) {
PaletteGroupView view = item.Client as PaletteGroupView;
foreach (Node n in view.Palette.Nodes) {
AddContextMenuItem(n);
}
}
}

I stored the palette node in the Tag of the context menu item. When the user clicked on a context menu item, i called the following method:

///
/// Adds a node to the diagram.
///

///
private void InsertNode(Node node) {
Node newNode = (Node)node.Clone();

//We want to insert node onto diagram at mouse location
newNode.PinPoint = diagram.Controller.MouseLocation;

//Add node to diagram
this.diagram.Model.AppendChild(newNode);
}

I hope someone may find this usefull.
Thanks.







J.Nagarajan [Syncfusion]
Replied On July 3, 2008 12:45 PM UTC

Hi Mcinp ,

Thanks for the code snippet for resolving this issue. InsertNodeCmd and Controller.ExecuteCommand() are no longer valid in v6.3.0.6. You can use Model.AppendChild() method to insert a node. Please refer to the following code snippet.

Rectangle m_rectangle1 = new Rectangle(60, 70, 120, 74);
this.diagram1.Model.AppendChild(m_rectangle1);

Please let me know if you have any other questions.

Thanks,
Nagaraj


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.

Warning Icon 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.Close Icon

;