Results 1 to 3 of 3

Thread: Advanced text coloring: RTF processing

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Advanced text coloring: RTF processing

    Hello everyone.

    Rather complicated question here. I am improving the text coloring in my custom RTB control, and it is pretty simple:
    1. Disable drawing (SetDrawing(False))
    2. Get current selection
    3. Select lines to colorize
    4. Process selection RTF vs selection Text
    5. Set old selection
    6. Enable drawing (SetDrawing(True))
    I have a problem at step 4. I need to set a "header" for the set RTF. I currently use this coding:
    Code:
        Public Sub UpdateColors()
            Dim tmprtb As New RichTextBox
            tmprtb.Font = Me.Font
            tmprtb.Text = ""
            Me._fontheader = tmprtb.Rtf.Split(vbCrLf)(0) & vbCrLf
            Me._fontheader &= "{\colortbl ;"
            Me._fontheader &= "\red" & Me.cf1.R & "\green" & Me.cf1.G & "\blue" & Me.cf1.B & ";"
            Me._fontheader &= "\red" & Me.cf2.R & "\green" & Me.cf2.G & "\blue" & Me.cf2.B & ";"
            Me._fontheader &= "\red" & Me.cf3.R & "\green" & Me.cf3.G & "\blue" & Me.cf3.B & ";"
            Me._fontheader &= "\red" & Me.cf4.R & "\green" & Me.cf4.G & "\blue" & Me.cf4.B & ";"
            Me._fontheader &= "\red" & Me.cf5.R & "\green" & Me.cf5.G & "\blue" & Me.cf5.B & ";"
            Me._fontheader &= "\red" & Me.cf6.R & "\green" & Me.cf6.G & "\blue" & Me.cf6.B & ";"
            Me._fontheader &= "\red" & Me.cf7.R & "\green" & Me.cf7.G & "\blue" & Me.cf7.B & ";}"
            Dim s As String = tmprtb.Rtf.Split(vbCrLf)(1)
            Me._fontheader &= vbCrLf & s.Substring(0, s.Length - 4)
            tmprtb.Dispose()
            tmprtb = Nothing
        End Sub
    Produces:
    {\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
    {\colortbl ;\red0\green0\blue0;\red0\green128\blue0;\red255\green128\blue0;\red0\green128\blue255;\red0\green0\ blue255;\red255\green0\blue0;\red128\green128\blue128;}

    \viewkind4\uc1\pard\f0\fs29
    The cf values are text colors used in the document. How can I accomplish the same thing without using a (new) RichTextBox control? Like, parse the information of a Font object.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width