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

Polygon Tool

hello,
I am using the polygon tools and i have a few questions:

1 -How can i change the color of the drawed polygon, by default it is yellow, i want it to be transparent.

2- How can i control the insert node event and delete node event.. for example when a polygon is inserted i want to change it's default name and when a polygone is deleted i want some code to be executed.

3- On doubleclicking a node, i want this node to be the selected node and also execute some code.

Thank you for you quick reply

Regards
Elie

3 Replies

J. J.Nagarajan Syncfusion Team September 3, 2007 08:44 PM UTC

Hi Elie,

Thanks for your continued interest in Syncfusion product.

1. To change the color of polygon, you have to derive PolygonTool class and override the CreateNode() method. Please refer to the following code snippet

public class MyPolygonTool: PolyLineBase
{
protected override Node CreateNode( PointF[] pts )
{
Polygon m_polygon = new Polygon(pts);
m_polygon.FillStyle.Color = Color.Transparent;
return (m_polygon);
}
}

// In Tool->Polygon menuitem's click event
private void menuItem2_Click(object sender, EventArgs e)
{
MyPolygonTool m_polygon = new MyPolygonTool(this.diagram1.Controller);
this.diagram1.Controller.RegisterTool(m_polygon);
this.diagram1.Controller.ActivateTool(m_polygon);
}

I have attached the sample that demonstrates this completely. You can download the sample from the following page.
http://websamples.syncfusion.com/samples/Diagram.Windows/F67863/main.htm

2. To change the node's name when it inserts into the diagram model then you have to handle EventSink.NodeCollectionChanged event. In this event you can add your code when you delete the selected node. Please refer to the following code snippet

this.diagram1.Model.EventSink.NodeCollectionChanged+=new CollectionExEventHandler(EventSink_NodeCollectionChanged);

[EventHandlerPriority(true)]
private void EventSink_NodeCollectionChanged(CollectionExEventArgs evtArgs)
{
// Control InsertNodeevent
if (evtArgs.ChangeType == CollectionExChangeType.Insert)
{
Node objnode = evtArgs.Element as Node;
objnode.Name = "PolygonNode";
Console.WriteLine(objnode.Name);
}

if (evtArgs.ChangeType == CollectionExChangeType.Remove)
{
Console.WriteLine("Removed the node from the Diagram");
}

}
Sample: http://websamples.syncfusion.com/samples/Diagram.Windows/F67863/main.htm

3. To achieve this you have to customize a node and you can perform the MouseDoubleClick event. Please refer to the following code snippet.

public class MySymbol : Group
{
protected override void OnMouseDoubleClick()
{
if (this.m_curEllipseColor == m_ellipseColors.Length - 1)
{
this.m_curEllipseColor = 0;
}
else
{
this.m_curEllipseColor++;
}
this.m_innerEllipse.FillStyle.Color = m_ellipseColors[this.m_curEllipseColor];

MessageBox.Show("NodeDoubleClick event gets fired");
}
}

I have attached the sample that demonstrates this completely. You can download the sample from the following page

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

Please refer to the sample and let me know if you have any questions.

Regards,
Nagaraj


EL Elie September 4, 2007 06:55 AM UTC

Thank you for your reply,
this was just the event that i needed.


J. J.Nagarajan Syncfusion Team September 6, 2007 08:52 PM UTC

Hi Elie,

Thanks for the update.

Please feel free to contact us if you have any other questions.

Thansk for your continued interest in Syncfusion product.

Regards,
Nagaraj

Loader.
Live Chat Icon For mobile
Up arrow icon