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

Correct way to resize nodes after creation

Hi Syncfusion,

Can you advise on the correct way to set the size of a node AFTER it's already been created (and given an initial size)? I've managed to use the below code to do it but i get strange positioning of highlight boxes when adding links once it's been resized.

Here's the code i was using to resize the nodes:
// create node
var n = new Rectangle(10,10,265,100,MeasureUnits.Pixel);
// to shrink
n.SetSize(new SizeF(265,100), new SizeF(265,60)); // old size followed by new size
n.CentralPort.OffSetX = 265/2;
n.CentralPort.OffsetY = 60/2;
// to expand
n.SetSize(new SizeF(265,60), new SizeF(265,100)); // new size followed by old size
n.CentralPort.OffSetX = 265/2;
n.CentralPort.OffsetY = 100/2;

Can somebody advise what I should be doing instead?

Thank you,
John



AddLinkProblem_f731de5f.zip

4 Replies

AA Amsath Ali M Syncfusion Team September 27, 2011 06:24 AM UTC

Hi Johnathan,

Thanks for your interest in Syncfusion products.

We suggest you to use the Node’s ‘Size’ property to change the size of the node after creating the node. Since the central port is automatically positioned in the center of the node when node’s size is changed, you need not to change its offsets. Please refer the below code snippet to achieve your requirement.

Here is the code:
//Gets/Sets the size of the node.
node.Size = new SizeF(70, 50);

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 set node size2058710948.zip

Regards,
Amsath Ali. M




JT Johnathan Tunnicliffe September 27, 2011 08:08 AM UTC

Hi Amsath Ali. M,

I had tried that before but for some reason the node isn't being having it's size property changed. I'm setting the size of the node in the setter of a property on the node itself.

I've overriden Rectangle and have a boolean property called ConciseMode. It's implementation looks like this:

private bool m_conciseMode;
public bool ConciseMode
{
get { return m_conciseMode; }
set {
if(value)
{
this.Size = new SizeF(265, 60);
}
else
{
this.Size = new SizeF(265, 100);
}

// whilst stepping over the code i can see the size of 'this' hasn't changed
m_conciseMode = value;
}
}

any idea why this could be happening whilst .SetSize appears to have an impact no the size?

Thanks,
John



JT Johnathan Tunnicliffe September 27, 2011 08:16 AM UTC

I've just figured out what it is.

I had the follwing properties set:
//this.EditStyle.AllowChangeHeight = false;
//this.EditStyle.AllowChangeWidth = false;

This is because i didn't want the user to be able to resize the nodes. But i did not realize it would mean i can't set the node size programatically. Is this also the case with AllowMoveX and AllowMoveY that I then can't programmatically move nodes (but want the users to not be able to drag the node)?

Thanks,
John



AA Amsath Ali M Syncfusion Team September 29, 2011 02:05 PM UTC

Hi Johnathan,

Thanks for the update.

When the Node.Editstyle’s “AllowChangeWidth and AllowChangeHeight” properties are set to ‘false’ then the node cannot be resized either by programmatically or by dynamically through by dragging the resize handle of node. Hence, we suggest you to set those Properties to ‘true’ before changing the size of the node by programmatically.
Please let us know if you have any queries.

Regards,
Amsath Ali. M



Loader.
Live Chat Icon For mobile
Up arrow icon