We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Changing color in a paragraph

I am attempting to change the color in a paragraph but only part of the paragraph.

Here is my code behind example...

slides(0).Shapes(2).TextFrame.Text = "Username = " & Me.lblUser.Text

slides(0).Shapes(2).TextFrame.Paragraphs(0).Portions(0).FontColor = Color.Red

I want the user to be in red but not the first part, "Username = "

So it would read "Username = Todd"

How can I do this in the code behind (vb.net)? The above code changes the entire line red.

Dim pres As New Presentation

Dim sld As Slide = pres.GetSlideByPosition(1)

Dim rect As Aspose.Slides.Rectangle

rect = sld.Shapes.AddRectangle(500, 500, 3000, 2000)

rect.LineFormat.ShowLines = False

Dim tf As TextFrame = rect.AddTextFrame("")

'The relevant code starts from here

Dim para As Paragraph

para = tf.Paragraphs(0)

Dim port As Portion

port = para.Portions(0)

port.Text = "Username = "

'Now the red colored name

'to do so, you will add a new portion object

'portion object is the object that holds indvidual textformatting

Dim newPort As New Portion(port)


'Set the text and color of new portion

newPort.Text = "Todd"

newPort.FontColor = Color.Red

'Write presentation on disk