How to change text color in a Node?

I'm having a problem programatically changing the color of the text of a label in a Node on in my diagram. I have looked for a property for text color in both the Label and RoundRect classes but do not see properties to set text color?

Thanks,
Bryan


2 Replies

J. J.Nagarajan Syncfusion Team July 14, 2008 01:53 PM UTC

Hi bbarnard ,

Sorry for the inconvenience caused. You can not set the text color to the labels. Please use our TextNode instead. You can group the textnode on the RoundedRect and display the text as the label.

TextNode n = new TextNode("Novo texto");
//To set TextColor.
n.FontColorStyle.Color = Color.Green;
n.SizeToText(SizeF.Empty);
n.PinPoint=new PointF(200, 200);
n.Size=new SizeF(100,40);
n.EnableCentralPort = true;
n.WrapText = true;
this.diagramWebControl.Model.AppendChild(n);

Please let me know if this helps.

Regards,
Nagaraj



J. J.Nagarajan Syncfusion Team July 15, 2008 04:30 AM UTC

Hi Bryan ,

To change the TextColor of a node, you have to derive the Label class and override the Render() method. You can change the text color in this Render() method. Please refer to the following code snippet.

class MyLabel:Label
{
public MyLabel(string Text)
{
this.Text = Text;

m_strText = this.Text;

}
protected override void Render(System.Drawing.Graphics gfx)
{

// calc position
PointF ptPrimitivePosition = GetPosition();

using (Font font = this.FontStyle.CreateFont())
{
// get string bounding rectangle
SizeF szStringSize = gfx.MeasureString(m_strText, font);
PointF ptRenderringOrigin = new PointF(ptPrimitivePosition.X - szStringSize.Width / 2
, ptPrimitivePosition.Y - szStringSize.Height / 2);
// draw text
gfx.DrawString(this.Text, font, new SolidBrush(Color.Green), ptRenderringOrigin.X, ptRenderringOrigin.Y);
}
}
}

//Add the CustomLabel to the node

Rectangle m_rect1 = new Rectangle(120, 90, 120, 60);
this.diagram1.Model.AppendChild(m_rect1);
Label m_Label = new MyLabel("CustomLabel");
m_Label.Position = Position.Center;
m_rect1.Labels.Add(m_Label);

Please use this code and let me know if this helps.

Regards,
Nagaraj


Loader.
Up arrow icon