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

Diagram - Select Node

Hi,

I have been trying to use the Windows Forms - Diagram features of you products.

I find that the documentation needs some work for a novice like myself using your controls to get started.

Nevertheless, I have been able to get started albeit with a fair amount of work was able to get started.

My issue is this:
I have a standard winforms button control on my form which when I click must change a particular node's (rectangle or polygon) colour and line width. I know the name of the node that needs to have the colour changed.

My second issue is:
How do iterate through all the nodes so that all nodes have a blue colour or a transparent colour.


Hope someone can help as they seem to be easy issues to solve - I just cannot find the documentation for this.




6 Replies

AA Amsath Ali M Syncfusion Team June 6, 2011 08:50 AM UTC

Hi Ahm,

Thanks for using Syncfusion products.

We suggest you to use the Node’d ‘Fillstyle.Color’ and ‘LineStyle.LineWidth’ property to change the clor and linewidth of a node respectively.
Please refer the below code snippet:

[C#]

Syncfusion.Windows.Forms.Diagram.Rectangle rect = new Syncfusion.Windows.Forms.Diagram.Rectangle(100, 100, 75, 50);
rect.FillStyle.Color = Color.Blue;
rect. LineStyle.LineWidth = 2;

To iterate through all the nodes in diagram control on the button click, we suggest you to use the following code snippet:

[C#]

NodeCollection nodes = this.diagram1.Model.Nodes;

foreach(FilledPath node in nodes)
{
if (node.Name == "Rectangle")
{
node.FillStyle.Color = Color.Yellow;
node.LineStyle.LineWidth = 2;
}
}

For your convenience, we have created a simple sample to achieve your requirement.
Please try the below sample and let us know if you have any queries.
forum changing fllstyl on btnclk782123536.zip

Regards,
Amsath Ali. M




AU Ahm user June 6, 2011 01:25 PM UTC

Thanks for your answer.

I had a look at the attached app.

My problem is that I know the name of the node (I do not know the shape and type of node) and I want to change the fillstyle.

Hope you can assist further.

Many thanks




AU Ahm user June 6, 2011 05:34 PM UTC

I got the procedure partially working in VB.NET.

I used the following:

'For all nodes
Dim nodes As NodeCollection = Me.Diagram1.Model.Nodes

For Each node As FilledPath In nodes
node.FillStyle.Color = Color.Yellow
node.FillStyle.ColorAlphaFactor = 255
node.LineStyle.LineWidth = 0
Next


'For a particular node
Dim nodes As NodeCollection = Me.Diagram1.Model.Nodes

For Each node As FilledPath In nodes
If node.Name = "Rectangle1" Then
node.FillStyle.Color = Color.Yellow
node.FillStyle.ColorAlphaFactor = 255
node.LineStyle.LineWidth = 0
End If
Next

The problem is that I have a bitmap on my diagram and therefore get the following error:

Unable to cast object of type 'Syncfusion.Windows.Forms.Diagram.BitmapNode' to type 'Syncfusion.Windows.Forms.Diagram.FilledPath'.


I also find that one has to iterate through all nodes just to select change the setting of one node - there has to be an easier way.




AA Amsath Ali M Syncfusion Team June 9, 2011 08:54 AM UTC

Hi Ahm,

Thanks for the update.

We suggest you to use the below code snippet to iterate through all the nodes in diagram control and change the fillstyle of particular node.
Please refer the below code snippet:
Dim nodes As NodeCollection = Me.diagram1.Model.Nodes
For Each node As Node In nodes
If TypeOf node Is FilledPath Then
If node.Name = "Rectangle" Then
Dim fnode As FilledPath = CType(node, FilledPath)
fnode.FillStyle.Color = Color.Aqua
node.LineStyle.LineWidth = 2
End If
If node.Name = "Ellipse" Then
Dim fnode As FilledPath = CType(node, FilledPath)
fnode.FillStyle.Color = Color.LightPink
End If
End If
Next node
For your convenience, we have created a simple sample to achieve your requirement.
Please try the below sample and let us know if you have any queries.
ChangingFillStyllinBtnClk460163111.zip

Regards,
Amsath Ali. M





RK RK July 21, 2011 08:13 AM UTC

i am using diagram control.how to get selected nodename in runtime.



AA Amsath Ali M Syncfusion Team July 26, 2011 05:14 PM UTC

Hi Rk,

Thanks for your interest in Syncfusion products.

We are glad to inform you that we have achieved your requirement.
Here is the sample:
Incident-node selected-1842278934.zip

Please try the above sample and let us know if you have any queries.

Regards,
Amsath Ali. M



Loader.
Live Chat Icon For mobile
Up arrow icon