Free Support Forum - aspose.com

Formatting text

hi Aspose.diagram support,

How can you format a text ?

As an example, I have a shape somewhere with an associated text.
I can write to value of the text, no problem.
Dim t1 As New Aspose.Diagram.Txt(waarde.ToString(“F1”))
shape.Text.Value.Clear()
shape.Text.Value.Add(t1)

But now I want to have part of the text in red and bold, another part in red, potentially in a different font.

How can I do this ?

thanks a lot for this great product,

guido
Hi Guido,

Thanks for your inquiry. While adding multiple text values to a shape, we can apply a different style on each text value. Here is the sample source code:

string fileName = "Drawing1.vsd";

Diagram diagram = new Diagram("C:\\" + fileName);

Shape shape = diagram.Pages[0].Shapes[0];

shape.Text.Value.Clear();

shape.Chars.Clear();

shape.Text.Value.Add(new Cp(0));

shape.Text.Value.Add(new Txt("TextStyle_Regular\n"));

shape.Text.Value.Add(new Cp(1));

shape.Text.Value.Add(new Txt("TextStyle_Bold_Italic\n"));

shape.Text.Value.Add(new Cp(2));

shape.Text.Value.Add(new Txt("TextStyle_Underline_Italic\n"));

shape.Text.Value.Add(new Cp(3));

shape.Text.Value.Add(new Txt("TextStyle_Bold_Italic_Underline"));

shape.Chars.Add(new Aspose.Diagram.Char());

shape.Chars.Add(new Aspose.Diagram.Char());

shape.Chars.Add(new Aspose.Diagram.Char());

shape.Chars.Add(new Aspose.Diagram.Char());

shape.Chars[0].IX = 0;

shape.Chars[0].Color.Value = "#FF0000";

shape.Chars[0].Font.Value = 4;

shape.Chars[0].Size.Value = 0.22;

shape.Chars[0].Style.Value = StyleValue.Undefined;

shape.Chars[1].IX = 1;

shape.Chars[1].Color.Value = "#FF00FF";

shape.Chars[1].Font.Value = 4;

shape.Chars[1].Size.Value = 0.22;

shape.Chars[1].Style.Value = StyleValue.Bold | StyleValue.Italic;

shape.Chars[2].IX = 2;

shape.Chars[2].Color.Value = "#00FF00";

shape.Chars[2].Font.Value = 4;

shape.Chars[2].Size.Value = 0.22;

shape.Chars[2].Style.Value = StyleValue.Underline | StyleValue.Italic;

shape.Chars[3].IX = 3;

shape.Chars[3].Color.Value = "#3333FF";

shape.Chars[3].Font.Value = 4;

shape.Chars[3].Size.Value = 0.22;

shape.Chars[3].Style.Value = StyleValue.Bold | StyleValue.Italic | StyleValue.Underline;

diagram.Save("C:\\Drawing1.vdx", SaveFileFormat.VDX);


I hope this will help you. Please let us know in case of further assistance and comments.