Hi Stoyan,
This is working but it is working everytime i.e I want to decrease the node's font size by 1. If now text is fit into the text area than no need to decrease font size any more but if it is not than again do the same till fontsize-3.
One more thing, if font size is 12 and text is small enough to fit into the text area than we don't need to decrease the font size.
The code for Shape is as follows
textOnTheRight = new MindFusion.Diagramming.Wpf.Shape(
Shapes.Rectangle.Outline,// reuse the rectangular shape
null,// no decorations
new ElementTemplate[]// define text region
{
new LineTemplate(32, 29, 90, 29),
new LineTemplate(90,29, 90, 69),
new LineTemplate(90, 69, 32, 69),
new LineTemplate(32, 69, 32, 29)
},
FillRule.EvenOdd,// doesn't matter here
"TextOnTheRight"// to access the shape later using Shape.FromId
);
The code for which I have tried is as follows
private void SetFontSize(ShapeNode node)
{
if (node != null)
{
Rect bounds = node.Bounds;
double textAreaWidth = bounds.Width * 58 / 100; // Width of the text area
double textAreaHeight = bounds.Height * 40 / 100; // Height of the text area
Size textSize = diagram.MeasureString(node.Text, node.Font, (int)textAreaWidth, node.TextFormat);
while (textSize.Height > textAreaHeight && node.Font.Size > 9)
{
node.Font.Size -= 1;
node.Repaint(false);
SetFontSize(node);
}
}
}
Please suggest which check I am missing?
Regards,
Anshul