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

add my own symbol into a palette

Hi,

I want to create my own symbol and add it on my own palette programmatically. Could you send me a sample?

I'm using this but it doesn't work propertly:

SymbolPalette paletteCur = symbolPaletteGroupBar.CurrentSymbolPalette;

Group mysymbolmdl = new Group();

int inicio;

mysymbolmdl.AppendChildren(this.diagram1.Model.Nodes, out inicio);

if (ZY8201.MessageBoxYesNo.Show(ec.messageOwnerName, 77, "info") == DialogResult

{

FrmNameSymbol frmNameSymbol = new FrmNameSymbol(this);

frmNameSymbol.ShowDialog();


if (nameSymbol != "")

{

mysymbolmdl.Name = nameSymbol;

}

}

paletteCur.AppendChild(mysymbolmdl);


I have to appendchild before naming the symbol, in other case a big red cross appear in the diagram. I don't know what i'm doing wrong.

I would appreciate any help. Thanks



10 Replies

NG Naganathan Ganesh Babu Syncfusion Team May 28, 2015 08:54 AM UTC

Hi Blanca,
 
Thanks for using Syncfusion product.
 
We are glad to inform you that we have created simple sample to achieve your requirement. Please refer the below code snippet and sample for your references.
 
Here is the code snippet:
[C#]
 

//Creates a Symbols programmatically

SymbolPalette symbol = new SymbolPalette();

symbol.Name = "Symbol";

symbol.AppendChild(Rectangle);

symbol.AppendChild(Ellipse);


//Creates a PaletteGroupBar programmatically

PaletteGroupBar paletteBar = new PaletteGroupBar();

paletteBar.Dock = DockStyle.Left;

paletteBar.Font = new Font("Arial", 9);

paletteBar.BorderStyle = BorderStyle.None;


//Apply visual styles

paletteBar.VisualStyle = Syncfusion.Windows.Forms.VisualStyle.Office2010;

paletteBar.TextAlign = Syncfusion.Windows.Forms.Tools.TextAlignment.Left;

paletteBar.ClientSize = new Size(200, 100);

paletteBar.Collapsed = false;

paletteBar.Enabled = true;

paletteBar.Visible = true;           


//Add symbols to palatte

paletteBar.AddPalette(symbol);


//Add paletteBar to the form
this.diagram1.Controls.Add(paletteBar);
 
Here is the sample:
Sample
 
Please let us know if any concerns.
 
Regards,
 
Naganathan K G



BC Blanca Calderon June 2, 2015 11:41 AM UTC

Hi,

thank you for the sample.

However I have another question, I want to insert rectangle and ellipse all together as a unique symbol.

I use the diagram as an area of drawing, if you want to draw more than one symbol for create your own symbol (for example rectangle+ellipse, name mynewsymbol) how do i make it?




NG Naganathan Ganesh Babu Syncfusion Team June 3, 2015 05:48 AM UTC

Hi Blanca,
 
Thanks for your update.
 
We are glad to inform you that we have created simple sample to achieve your requirement. We suggest you to use Group node to create Group symbols and add these symbols to the SymbolPalatte in order to achieve your requirement. Please refer the below code snippet and sample for your references.
 
Here is the code snippet:
[C#]

Syncfusion.Windows.Forms.Diagram.Rectangle Rectangle = new Syncfusion.Windows.Forms.Diagram.Rectangle(100, 100, 100, 50);

Rectangle.FillStyle.Color = Color.SkyBlue;

Syncfusion.Windows.Forms.Diagram.Ellipse Ellipse = new Syncfusion.Windows.Forms.Diagram.Ellipse(0, 60, 100, 100);

Ellipse.FillStyle.Color = Color.SeaGreen;


Group grp = new Group();

grp.Name = "MyNewSymbol";

grp.AppendChild(Rectangle);
grp.AppendChild(Ellipse);

//Creates a Symbols programmatically

SymbolPalette symbol = new SymbolPalette();

symbol.Name = "Symbol";
symbol.AppendChild(grp);
 
Here is the sample:
Sample
 
Please let us know if any concerns.
 
Regards,
 
Naganathan K G



BC Blanca Calderon June 4, 2015 11:07 AM UTC

Hi,

group node works fine. The problem is when I try to name the new symbol using a form. A big cross appears instead of the diagram.

It works perfect if I put a name programmatically:

Group grp = new Group();

grp.Name = "MyNewSymbol";

for (int i = 0; i < this.diagram1.Model.Nodes.Count; i++)

{

grp.AppendChild(this.diagram1.Model.Nodes[i]);

}

SymbolPalette paletteCur = symbolPaletteGroupBar.CurrentSymbolPalette;

paletteCur.AppendChild(grp);


But if I use this instead of grp.Name = "mysymbol" it doesn't work:

if (ZY8201.MessageBoxYesNo.Show(ec.messageOwnerName, 77, "info") == DialogResult.Yes)
{
FrmNameSymbol frmNameSymbol = new FrmNameSymbol(this);
frmNameSymbol.ShowDialog();
if (nameSymbol != "")
{
grp.Name = nameSymbol;
}

















































































































































  




BC Blanca Calderon June 4, 2015 11:18 AM UTC

The big cross appears after close the form I use for naming my element. If I go to select other symbol in my palette or click inside the diagram appears.


NG Naganathan Ganesh Babu Syncfusion Team June 5, 2015 09:55 AM UTC

Hi Blanca,
 
Thanks for your update.
 
We are unable reproduce the reported issue at our end. We have modified your code snippet and created the simple sample to achieve your requirement. We suggest you to use Node’s Clone() method while append in the group node. Please refer the below sample and code snippet for your references.
 
Here is the code snippet:
[C#]

Group grp = new Group();

grp.Parent = diagram1.Model;

grp.Name = "mysymbol";

for (int i = 0; i < this.diagram1.View.SelectionList.Count; i++)

{

Node nod = this.diagram1.View.SelectionList[i].Clone() as Node;

grp.AppendChild(nod);

}

 
Here is the sample:
Sample
 
Here is the video:
Video
 
If we misunderstood your requirement, could you please share us more information of your requirement to adding name for group node probably sample or video which will help us to analyze further and provide better solution?
 
Please let us know if any concerns.
 
Regards,
 
Naganathan K G



BC Blanca Calderon June 5, 2015 11:02 AM UTC

Oh my god, what difficult is this:-(

I don't have problems adding nodes into a group, I have problems when I name my new symbol outside with a new form. 

grp.name = "blablabla" works fine

if I use a new form with a textbox where a client could insert the name they want, it doesn't work!! Is it so difficult to understand? 

Your sample is fantastic but you don't use a form for the name, you put it programmatically and I need the client could put the name they want.



Attachment: Video_1433508993_715381af.zip


BC Blanca Calderon replied to Blanca Calderon June 5, 2015 11:11 AM UTC

Oh my god, what difficult is this:-(

I don't have problems adding nodes into a group, I have problems when I name my new symbol outside with a new form. 

grp.name = "blablabla" works fine

if I use a new form with a textbox where a client could insert the name they want, it doesn't work!! Is it so difficult to understand? 

Your sample is fantastic but you don't use a form for the name, you put it programmatically and I need the client could put the name they want.



Attachment: Video_1433508993_715381af.zip

As you could see on the video I don't have problems creating a new symbol (with a group of two diffent images). If I don't open a new form to name the new symbol I don't have problem, if I use an "external" form to name it when I click on the new symbol a big cross appear.

I don't know where is the problem, but it exists and this is the second thread I open with this issue.

I sent you a video in the previous thread and now the code I'm using, I don't know what else could do, it's a bit hopeless.





BC Blanca Calderon replied to Blanca Calderon June 5, 2015 11:16 AM UTC

Oh my god, what difficult is this:-(

I don't have problems adding nodes into a group, I have problems when I name my new symbol outside with a new form. 

grp.name = "blablabla" works fine

if I use a new form with a textbox where a client could insert the name they want, it doesn't work!! Is it so difficult to understand? 

Your sample is fantastic but you don't use a form for the name, you put it programmatically and I need the client could put the name they want.



Attachment: Video_1433508993_715381af.zip

As you could see on the video I don't have problems creating a new symbol (with a group of two diffent images). If I don't open a new form to name the new symbol I don't have problem, if I use an "external" form to name it when I click on the new symbol a big cross appear.

I don't know where is the problem, but it exists and this is the second thread I open with this issue.

I sent you a video in the previous thread and now the code I'm using, I don't know what else could do, it's a bit hopeless.




And please you don't close this thread if I don't response in a few days, I will be outside next week but when I come back the problem will be there and I will need a solution.


NG Naganathan Ganesh Babu Syncfusion Team June 8, 2015 07:31 AM UTC

Hi Blanca,
 
Thanks for your update and sorry for the inconvenience caused.
 

I don't have problems adding nodes into a group, I have problems when I name my new symbol outside with a new form. 


grp.name = "blablabla" works fine


if I use a new form with a textbox where a client could insert the name they want, it doesn't work!! Is it so difficult to understand? 


We are unable to reproduce reported issue at our end. We have modified the sample and also using new Form for set name for the node. Please refer the below code snippet and modified sample for your references.


Here is the code snippet:


[C#]


private void button1_Click(object sender, EventArgs e)

{

if(diagram1.View.SelectionList.Count > 0)

{

Group grp = new Group();

form2 = new Form2();

Button button = new Button();

button.Text = "OK";

button.Size = new System.Drawing.Size(100, 20);

TextBox text = new TextBox();

text.Multiline = true;

text.Size = new Size(270, 150);

if (!form2.Controls.Contains(text))

form2.Controls.Add(text);

if (!form2.Controls.Contains(button))

form2.Controls.Add(button);

form2.Location = new Point((int)diagram1.Controller.MouseLocation.X, (int)diagram1.Controller.MouseLocation.Y);

                text.Location = new Point(0, 0);

                button.Location = new Point(100, 160);


for (int i = this.diagram1.View.SelectionList.Count - 1; i >= 0; i--)

{

Node nod = this.diagram1.View.SelectionList[i].Clone() as Node;

if (i != this.diagram1.View.SelectionList.Count - 1)

{

  nod.PinPoint = new PointF(Math.Abs(this.diagram1.View.SelectionList[i + 1].PinPoint.X - nod.PinPoint.X), Math.Abs(this.diagram1.View.SelectionList[i + 1].PinPoint.Y - nod.PinPoint.Y));

}

grp.AppendChild(nod);

 }

button.Click += button_Click;

form2.ShowDialog();

 grp.Name = text.Text;

 symbol.AppendChild(grp);

}

}


Here is the modified sample:


Sample



 
Please let us know if any concerns.
 
Regards,
 
Naganathan K G

Loader.
Up arrow icon