Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Non Rotatable Label for Shapenode in .net (Read 118 times)
G_G
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Dec 8th, 2021
Non Rotatable Label for Shapenode in .net
Aug 7th, 2024 at 7:50am
Print Post  
Hi I'm trying to have a shapenode in my diagram that has a label centered below it that is rotatable without the label changing position or orientation. I cant figure out how.
I know node.text can be set to not rotate but i cant position it below the node outline
If at all possible i would like to avoid using a dedicated textnode for this because i would have to change a lot of code to do so.
Does anyone know a solution to this?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3228
Joined: Oct 19th, 2005
Re: Non Rotatable Label for Shapenode in .net
Reply #1 - Aug 7th, 2024 at 9:34am
Print Post  
Hi,

If you don't mind using a custom class, you could override the Draw method:

Code
Select All
class ShapeNodeEx : ShapeNode
{
	StringFormat labelFormat = new StringFormat
	{
		LineAlignment = StringAlignment.Near,
		Alignment = StringAlignment.Center
	};

	public override void Draw(IGraphics graphics, RenderOptions options)
	{
		options.EnableText = false;
		base.Draw(graphics, options);
		options.EnableText = true;

		var textRect = GetRotatedBounds();
		textRect.Y += textRect.Height + 1;
		graphics.DrawString(
			Text, EffectiveFont, Brushes.Black,
			textRect, labelFormat);
	}

	public override RectangleF GetRepaintRect(bool includeConnected)
	{
		var repaintRect = base.GetRepaintRect(includeConnected);
		var textRect = GetRotatedBounds();
		textRect.Y += textRect.Height + 1;
		return RectangleF.Union(repaintRect, textRect);
	}
} 



Otherwise you could probably push the text below node by setting TextPadding while RotateText is disabled, but would have to modify padding dynamically when node rotates.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
G_G
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 16
Joined: Dec 8th, 2021
Re: Non Rotatable Label for Shapenode in .net
Reply #2 - Aug 14th, 2024 at 6:10am
Print Post  
Thanks this solves this issue for us!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint