Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Different text styles when draw labels from DrawNode event handler (Read 2136 times)
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Different text styles when draw labels from DrawNode event handler
Aug 10th, 2014 at 7:10am
Print Post  
Hi Stoyan,

This question actually connected with another one (http://mindfusion.eu/Forum/YaBB.pl?num=1407499104). But I would have separated it.

When I draw an additional labels, there is the same font style as for the node:
Code
Select All
var node = e.Node;
...
diagram.DrawStyledText(e.Graphics, label, node, labelRect);
 


I tried to create a new TextAttributes to use instead (I need a smaller font, in different color and not bold as node's text for this additional labels):
Code
Select All
var txtAttr = new TextAttributes(node) { FontSize = 7, FontStyle = System.Windows.FontStyles.Normal, TextBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF0070E0")) };
 


The problem is that FontSize works, but it does not affect the FontStyle and BrushColor. Can I define all this settings separately from the node's text style?

Thanks,
-Kostya
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Different text styles when draw labels from DrawNode event handler
Reply #1 - Aug 11th, 2014 at 10:32am
Print Post  
Hi Kostya,

DrawStyledText ignores font style and color attributes and instead applies respective attributes defined via HTML tags in the text. In order to use different styles and colors with DrawStyledText, add the formatting elements listed here to the labels:
http://www.mindfusion.eu/onlinehelp/wpfdiagram/index.htm?CC_Text_Attributes_and_...

Alternatively, instead of DrawStyledText you could render labels using DrawingContext.DrawText method to use specified TextAttributes values. E.g. create a FormattedText object like this:

Code
Select All
var typeface = new Typeface(
    textAttributes.FontFamily,
    textAttributes.FontStyle,
    textAttributes.FontWeight,
    textAttributes.FontStretch);

var text = new FormattedText(label,
    System.Globalization.CultureInfo.CurrentCulture,
    FlowDirection.LeftToRight,
    typeface,
    textAttributes.FontSize,
    textAttributes.TextBrush);

r.Graphics.DrawText(graphics, text, labelRect.Location); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Different text styles when draw labels from DrawNode event handler
Reply #2 - Aug 11th, 2014 at 12:19pm
Print Post  
Hi Stoyan,

Thanks much! I picked the DrawStyledText way, since it is shorter, and I suspect that the similar operations with the text occur in the background anyway.

-Kostya
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint