Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ShapeNode - formating of an additional text (Read 1707 times)
Olejan
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 12
Joined: Apr 5th, 2016
ShapeNode - formating of an additional text
Apr 5th, 2016 at 9:48am
Print Post  
Hi,
I am editing some code and using WPF Diagramming. I have a ShapeNode and I would like to show some aligned wrapped additional text above the shape.

I have this code to set additional text:
Code
Select All
public void DrawNode(DrawingContext a_Context, FontFamily a_FontFamily, FontStretch a_FontStretch)
{
   Typeface tface = new Typeface(a_FontFamily, FontStyle,  FontWeight, a_FontStretch);
   Point txtLocation = new Point(5, 65);
   FormattedText text = new FormattedText("Additional text that is located above",
                      CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                      tface, FontSize, Brushes.Black);
   a_Context.DrawText(text, txtLocation);
}
 


But the "Additional text that is located above" is not alligned and wrapped.
If I change proprties TextAlignment and TextWrapping in the DrowNode function it is just changing formating of the "Main text of node".
Code
Select All
...
   FormattedText text = new FormattedText("Additional text that is located above",
                      CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                      tface, FontSize, Brushes.Black);
   TextAlignment = System.Windows.TextAlignment.Center;
   TextWrapping = System.Windows.TextWrapping.Wrap;
   a_Context.DrawText(formtxt, txtLocation);
}
 


How can I achieve formatting of an additional text?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: ShapeNode - formating of an additional text
Reply #1 - Apr 5th, 2016 at 10:46am
Print Post  
Hi,

You could call diagram's DrawStyledText method for ready-made multiline formatting -

Code
Select All
void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
	// use CustomDraw.Additional2, or the text will get clipped
	var labelRect = new Rect(0, -200, e.Node.Bounds.Width, 200);
	diagram.DrawStyledText(e.Graphics,
		"Additional text that is located above",
		new TextAttributes(e.Node)
		{
			TextAlignment = TextAlignment.Center,
			TextVerticalAlignment = AlignmentY.Bottom
		},
		labelRect);
}
 



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


I Love MindFusion!

Posts: 12
Joined: Apr 5th, 2016
Re: ShapeNode - formating of an additional text
Reply #2 - Apr 5th, 2016 at 11:11am
Print Post  
Thank you so much! That's what I need
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint