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

Update node label position

Hi,
Im using this code to calculate node's label position:

label.Position = Position.Custom;
label.OffsetX = node.Size.Width / 2;
label.OffsetY = node.Size.Height + 20;

How to recalculate label position automatically when user resize node?


1 Reply

PM Pandi Murugan A Syncfusion Team October 5, 2010 01:13 PM UTC

Hi Witold,

Thank you for your interest in Syncfusion Products.

We suggest you to use Diagram DocumentEventSink's SizeChanged event to update the Node's Label position. Please refer the below code snippet.


[C#]
public Form1()
{
InitializeComponent();
((DocumentEventSink)diagram1.Model.EventSink).SizeChanged+=new SizeChangedEventHandler(Form1_SizeChanged);
}

void Form1_SizeChanged(SizeChangedEventArgs evtArgs)
{
//update the label position here
PathNode node = evtArgs.NodeAffected as PathNode;
if (node.Labels.Count > 0)
if (node.Labels[0] != null)
{
node.Labels[0].OffsetX = node.Size.Width / 2;
node.Labels[0].OffsetY = node.Size.Height + 20;
}
}


For your convenience, we have created a simple sample and the same can be downloaded from below link.

LabelPosition648179222.zip

Please let me know if you have any concerns.

Regards,
Pandi Murugan A



Loader.
Live Chat Icon For mobile
Up arrow icon