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

In the textnode how to get the height by width and font size?

In the textnode how to get the height by width and font size?


4 Replies

AA Amsath Ali M Syncfusion Team November 28, 2011 10:44 AM UTC

Hi Songjian,

Thanks for your interest in Syncfusion products.

We suggest you to use the TextNode.BoundingRectangle’s ‘Width and Height’ properties to get height and width of the node respectively and use TextNode.FontStyle’s ‘Size’ property to get the size of the font in TextNode. Please refer the below code snippet to achieve your requirement.

Here is the code:
[C#]
//Getting TextNode's properties in ButtonClick
private void button1_Click(object sender, EventArgs e)
{
if (diagram1.View.SelectionList.Count != 0)
{
foreach (Node node in diagram1.View.SelectionList)
{
if (node is TextNode)
{
float width = ((TextNode)node).BoundingRectangle.Width;
float height = ((TextNode)node).BoundingRectangle.Height;
float fntSize = ((TextNode)node).FontStyle.Size;
MessageBox.Show("Width:" + width + " " + "Height:" + height + " " + "Font Size:" + fntSize);
}
}
}
else
MessageBox.Show("Please select a TextNode");
}

Here is the Sample:
ForumGetTextNodeProp53894176.zip

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

Regards,
Amsath Ali. M





SO songjian November 28, 2011 02:25 PM UTC

When there are one more space in the textnode and I set the wrap property of textnode and the text length exceeds the textnode width,the line wrap exists.I don't to expect lines warp,how to solve it.Thank you!



SO songjian November 28, 2011 02:38 PM UTC

Sorry, I think I can't accurately express my question. My question is that how to get the textnode height when the textnode width and font size is known.Thank you!



PM Pandi Murugan A Syncfusion Team December 2, 2011 05:55 AM UTC

Hi Songjian,

We regret for the delay in getting back to you.

Please note that the TextNode’s Width/Height are not related to font size and they return Node’s bounds size. You can get the TextNode’s height by either BoundingRectangle.Height or TextNode.Size.Height.

Please let me know if you have any concerns.

Regards,
Pandi Murugan A



Loader.
Live Chat Icon For mobile
Up arrow icon