0

Possible Duplicate:
How to color individual characters and maintain proper spacing / kerning / alignment?

Using GDI+, I would like to break a string up into individual characters so I can change the font type, size, or weight at any point within the string.

Usage Examples:

  1. ****B****olding the first character.

  2. Using the Old English font for the first character (i.e. "Once upon a time" -> "O" = Old English font)

  3. Underlining a specific word (group of characters) within a sentence.

I cannot find any examples. I'm not sure how to approach this.

Public Class Character
    Public Property ID As Integer
    Public Property Value As Char
    Public Property CharacterFont As Font
    Public Property CharacterColor As Brush

    Public Sub New()
        CharacterFont = New Font("Times New Roman", 12)
    End Sub
End Class

......

Public Class CharacterBlock
    Private _characters As New List(Of Character)
    Public Property Alignment As StringAlignment

    Public Sub New()
        Alignment = StringAlignment.Center
    End Sub

    Public Sub New(p_characters As List(Of Character))
        Me.New()
        _characters = p_characters
    End Sub

    Public Sub New(p_characters As String)
        Me.New()
        _characters = (From s In p_characters.ToList Select New Character With {.Value = s}).ToList
    End Sub

    Public Sub New(p_characters As String, p_font As System.Drawing.Font)
        Me.New()
        _characters = (From s In p_characters.ToList Select New Character With {.Value = s, .CharacterFont = p_font}).ToList
    End Sub

    'TODO: Add methods to measure and draw character blocks 
End Class
Community
  • 1
  • 1
user1932634
  • 181
  • 12

1 Answers1

0

As far as I know there is nothing built in that way... you should do all the logic of drawing the character blocks, that being in just one line is quite "easy" but handling the end of the line and start writting in the next line could be tricky.

In order to have the user to change and format texts, what I would use is a RichTextBox.

There are some controls that makes using RichTextBox easier, this is one of them: http://www.codeproject.com/Articles/30799/Extended-RichTextBox

Once you have the text editor that allow user to format things, you need to print it. Here are some examples of how to print RichTextBox content:

You can add the code that makes the magic of printing RichTextBox content in the Extended RichTextBox Control.

Romias
  • 13,783
  • 7
  • 56
  • 85