Solved

richtext box

Posted on 2004-08-05
30
755 Views
Last Modified: 2010-05-18
i need to add a richtext box to my web form
the only functionality needed is to have a textbox where i can specify the color of the text (different paragraphs might have different colors)
0
Comment
Question by:razo
  • 10
  • 10
  • 8
30 Comments
 
LVL 8

Author Comment

by:razo
Comment Utility
forgot to say i want something for free
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Do you mean literally rich text, as in producing RTF output, or just a way of inputting formatted text? The link below is a good editor, but produces HTML.

http://www.fckeditor.net/
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
0
 
LVL 8

Author Comment

by:razo
Comment Utility
let me be specific
i want a textbox contol that allows me to display text with different colors
i dont want the toolbar accompanied with all richtextboxes...the user is not allowed to change the color
the output would still be text saved into a file and the colors are not needed to be saved
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Do you want several colours at the same time in the text box, one word in red, another in green etc? If so, the output would contain the formatting tags and you would have to remove them, e.g. your returned output might be something like:

    <font color=red>Here is some red text</font> and here is some <font color=green>green text</font>

It sounds like what you want is to get back just the text, without any formatting. Is that correct?

If you want all of the text in one colour, just set the ForeColor property of the textbox.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
no each word might have adifferent color
and yest i dont need the formatting as output...just the text
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Then you will have to use a control like freetextbox mentioned above. The toolbars are configurable, so you can (probably) turn them all off. However, you will get text back that contains formatting, so you will have to strip that out to get the bare text. That shouldn't be too difficult, write a function to look for an opening "<", if it's found look for the closing ">" and delete all characters in between. Loop through until there are no more matches. If you decide to go down this route and need help, I'll write the function for you.
0
 
LVL 8

Author Comment

by:razo
Comment Utility
let me see if there is a better option if not ill use ur way
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok i tried this control but i wasnt able to remove the toolbars and to define the color of the text programatically
give me the code and ill accept this question
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Here ya go :
'Name             : clsColorRichTextBox
'Description      : Class for coloring and format syntax in System.Windows.Forms.RichTextBox
'Publish Date     : 24.07.2003
'Legal Copyright  : © Rostislav V. Konnov, 2003
'Software Licence : Freeware
'Author           : Rostislav V. Konnov
'E-mail           : bigroko@mail.ru
'ICQ              : 38880828

Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

Namespace ColorRichTextBox

    Namespace WIN32API

        Public Module WIN32API

            Public Declare Function LockWindowUpdate Lib "user32" _
                (ByVal hWndLock As Integer) As Integer
            Public Declare Function GetDesktopWindow Lib "user32" _
                Alias "GetDesktopWindow" () As Integer
            Public Declare Function SendMessage Lib "user32" _
                Alias "SendMessageA" _
                (ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
                ByVal wParam As Integer, ByVal lParam As Integer) As Integer
            Public Declare Function SendMessage Lib "user32" _
                Alias "SendMessageA" _
                (ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
                ByVal wParam As Integer, ByRef lParam As CHARFORMAT) As Integer
            Public Declare Function SendMessage Lib "user32" _
                Alias "SendMessageA" _
                (ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
                ByVal wParam As Integer, ByVal lParam As String) As Integer

            Public Const EM_LINEFROMCHAR As Int32 = &HC9
            Public Const EM_LINEINDEX As Int32 = &HBB
            Public Const EM_LINELENGTH As Int32 = &HC1
            Public Const EM_REPLACESEL As Int32 = &HC2
            Public Const EM_SETSEL As Int32 = &HB1

            Public Const WM_USER As Int32 = &H400
            Public Const EM_GETCHARFORMAT As Int32 = (WM_USER + 58)
            Public Const EM_SETCHARFORMAT As Int32 = (WM_USER + 68)

            Public Const SCF_SELECTION As Int32 = &H1

            Public Const CFM_BOLD As Int32 = &H1
            Public Const CFM_CHARSET As Int32 = &H8000000
            Public Const CFM_COLOR As Int32 = &H40000000
            Public Const CFM_FACE As Int32 = &H20000000
            Public Const CFM_ITALIC As Int32 = &H2
            Public Const CFM_OFFSET As Int32 = &H10000000
            Public Const CFM_PROTECTED As Int32 = &H10
            Public Const CFM_SIZE As Int32 = &H80000000
            Public Const CFM_STRIKEOUT As Int32 = &H8
            Public Const CFM_UNDERLINE As Int32 = &H4

            Public Const CFE_AUTOCOLOR As Int32 = &H40000000
            Public Const CFE_BOLD As Int32 = &H1
            Public Const CFE_DISABLED As Int32 = &H2000
            Public Const CFE_ITALIC As Int32 = &H2
            Public Const CFE_PROTECTED As Int32 = &H10
            Public Const CFE_STRIKEOUT As Int32 = &H8
            Public Const CFE_UNDERLINE As Int32 = &H4

            Public Const LF_FACESIZE As Integer = 32

            <StructLayoutAttribute(LayoutKind.Sequential)> _
            Public Structure CHARFORMAT
                Dim cbSize As Int32
                Dim dwMask As Int32
                Dim dwEffects As Int32
                Dim yHeight As Int32
                Dim yOffset As Int32
                Dim crTextColor As Int32
                Dim bCharSet As Byte
                Dim bPitchAndFamily As Byte
                <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=LF_FACESIZE)> _
                Dim szFaceName As String
            End Structure

        End Module

    End Namespace

    Public Class clsColorRichTextBox

#Region " Constructors "

        Public Sub New(ByVal rtbControl As System.Windows.Forms.RichTextBox)
            Me.New(rtbControl, _
            New clsColorRichTextBoxSchema( _
                clsColorRichTextBoxSchema.enColorSchemaType.VBNET), _
            True)
        End Sub

        Public Sub New(ByVal rtbControl As System.Windows.Forms.RichTextBox, _
            ByVal rtbColorSchema As ColorRichTextBox.clsColorRichTextBoxSchema)
            Me.New(rtbControl, rtbColorSchema, True)
        End Sub

        Public Sub New(ByVal rtbControl As System.Windows.Forms.RichTextBox, _
            ByVal rtbColorSchema As ColorRichTextBox.clsColorRichTextBoxSchema, _
            ByVal bColorCode As Boolean)
            RichTextBoxControl = rtbControl
            ColorSchema = rtbColorSchema
            m_bColorCode = bColorCode
            m_rtbControl.ForeColor = m_ColorSchema.NormalColor
            m_rtbControl.Font = m_ColorSchema.NormalFont
        End Sub

#End Region

#Region " Private properties "

        Private bIsPaste As Boolean
        Private iPreviousLineIndex As Integer = 0
        Private iPreviousTextLength As Integer = 0
        Private bIsProcessingText As Boolean = False
        Private Matches As MatchCollection

#End Region

#Region " Public properties "

        Private WithEvents m_rtbControl As _
            System.Windows.Forms.RichTextBox
        Private m_bColorCode As Boolean = True
        Private m_ColorSchema As clsColorRichTextBoxSchema

        Public Property RichTextBoxControl() As _
            System.Windows.Forms.RichTextBox
            Get
                Return m_rtbControl
            End Get
            Set(ByVal Value As System.Windows.Forms.RichTextBox)
                m_rtbControl = Value
            End Set
        End Property

        Public Property ColorCode() As Boolean
            Get
                Return m_bColorCode
            End Get
            Set(ByVal Value As Boolean)
                m_bColorCode = Value
                If m_bColorCode = False Then UnColorEntireText()
            End Set
        End Property

        Public Property ColorSchema() As clsColorRichTextBoxSchema
            Get
                Return m_ColorSchema
            End Get
            Set(ByVal Value As clsColorRichTextBoxSchema)
                m_ColorSchema = Value
            End Set
        End Property

#End Region

#Region " Private methods "

        Private Sub ProcessString(ByVal sString As String)
            bIsProcessingText = True
            Dim iCurrentLineStartPosition As Integer = _
                GetCurrentLineStartPosition()

            WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                iCurrentLineStartPosition, _
                iCurrentLineStartPosition + sString.Length)
            WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETCHARFORMAT, _
                WIN32API.SCF_SELECTION, m_ColorSchema.CharFormatNormalText)

            Dim slExcludeSpaces As New SortedList()
            Dim iCount As Integer

            'Coloring strings
            If Not sString.IndexOf("""") = -1 _
                AndAlso Not m_ColorSchema.RegexPatternString = String.Empty Then
                Matches = Regex.Matches(sString, m_ColorSchema.RegexPatternString)
                For iCount = 0 To Matches.Count - 1
                    WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                        Matches(iCount).Index + iCurrentLineStartPosition, _
                        Matches(iCount).Index + iCurrentLineStartPosition + Matches(iCount).Length)
                    WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETCHARFORMAT, _
                        WIN32API.SCF_SELECTION, m_ColorSchema.CharFormatString)
                    slExcludeSpaces.Add(Matches(iCount).Index + iCurrentLineStartPosition, _
                        Matches(iCount).Index + iCurrentLineStartPosition + Matches(iCount).Length)
                Next iCount
            End If

            'Coloring line comments
            If Not sString.IndexOf(m_ColorSchema.LineComment) = -1 _
                AndAlso Not m_ColorSchema.RegexPatternLineComment = String.Empty Then
                Matches = Regex.Matches(sString, m_ColorSchema.RegexPatternLineComment)
                For iCount = 0 To Matches.Count - 1
                    If Not IsInExcludeSpace(Matches(iCount).Index + iCurrentLineStartPosition, _
                        slExcludeSpaces) Then
                        WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                            Matches(iCount).Index + iCurrentLineStartPosition, _
                            Matches(iCount).Index + iCurrentLineStartPosition + Matches(iCount).Length)
                        WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETCHARFORMAT, _
                        WIN32API.SCF_SELECTION, m_ColorSchema.CharFormatLineComment)
                        slExcludeSpaces.Add(Matches(iCount).Index + iCurrentLineStartPosition, _
                            Matches(iCount).Index + iCurrentLineStartPosition + Matches(iCount).Length)
                    End If
                Next iCount
            End If

            'Coloring keywords
            If Not m_ColorSchema.RegexPatternKeyword = String.Empty Then
                If m_ColorSchema.CaseSensitive Then
                    Matches = Regex.Matches(sString, m_ColorSchema.RegexPatternKeyword)
                Else
                    Matches = Regex.Matches(sString, m_ColorSchema.RegexPatternKeyword, _
                        RegexOptions.IgnoreCase)
                End If
                For iCount = 0 To Matches.Count - 1
                    If Not IsInExcludeSpace(Matches(iCount).Index + iCurrentLineStartPosition, _
                        slExcludeSpaces) Then
                        WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                            Matches(iCount).Index + iCurrentLineStartPosition, _
                            Matches(iCount).Index + iCurrentLineStartPosition + Matches(iCount).Length)
                        WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETCHARFORMAT, _
                            WIN32API.SCF_SELECTION, m_ColorSchema.CharFormatKeyword)
                       'Coloring keywords
                        If Not m_ColorSchema.CaseSensitive AndAlso m_ColorSchema.FormatKeyword Then
                            If m_ColorSchema.slKeywords.Contains(Matches(iCount).Value.ToLower) Then
                                WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_REPLACESEL, 0, _
                                    m_ColorSchema.slKeywords(Matches(iCount).Value.ToLower).ToString)
                            End If
                        End If
                    End If
                Next iCount
            End If

            bIsProcessingText = False
        End Sub

        Private Function IsInExcludeSpace(ByVal iIndex As Integer, _
            ByVal slExcludeSpaces As SortedList) As Boolean
            If slExcludeSpaces.Keys.Count = 0 Then Return False
            Dim aList As New ArrayList(slExcludeSpaces.Keys)
            Dim iFoundIndex As Integer = GetExcludeClosestStartPosition(iIndex, aList)
            If iFoundIndex = -1 Then Return False
            If iIndex < CInt(slExcludeSpaces(slExcludeSpaces.GetKey(iFoundIndex))) Then
                Return True
            Else
                Return False
            End If
        End Function

        Private Function GetExcludeClosestStartPosition(ByVal iIndex As Integer, _
            ByVal aList As ArrayList) As Integer
            Dim iFoundIndex As Integer = aList.BinarySearch(iIndex)
            If iFoundIndex < 0 Then
                iFoundIndex = Not iFoundIndex
                If Not iFoundIndex = 0 Then
                    iFoundIndex -= 1
                    Return iFoundIndex
                Else
                    Return -1
                End If
            Else
                Return iFoundIndex
            End If
        End Function

        Private Sub LockWindow(ByVal bLock As Boolean)
            If bLock Then
                WIN32API.LockWindowUpdate(WIN32API.GetDesktopWindow())
            Else
                WIN32API.LockWindowUpdate(Nothing)
            End If
        End Sub

        Private Function GetCurrentLineStartPosition() As Integer
            Return WIN32API.SendMessage(m_rtbControl.Handle, _
                WIN32API.EM_LINEINDEX, GetCurrentLineIndex(), 0)
        End Function

        Private Function GetCurrentLineString() As String
            Try
                Return m_rtbControl.Lines(GetCurrentLineIndex())
            Catch ex As Exception
                Return String.Empty
            End Try
        End Function

        Private Function GetCurrentLineIndex() As Integer
            Return WIN32API.SendMessage(m_rtbControl.Handle, _
                WIN32API.EM_LINEFROMCHAR, -1, 0)
        End Function

        Private Function GetCurrentLineLength() As Integer
            Return WIN32API.SendMessage(m_rtbControl.Handle, _
                WIN32API.EM_LINELENGTH, m_rtbControl.SelectionStart, 0)
        End Function

        Private Function GetLineLength(ByVal iLineIndex As Integer) As Integer
            Return WIN32API.SendMessage(m_rtbControl.Handle, _
                WIN32API.EM_LINELENGTH, iLineIndex, 0)
        End Function

#End Region

#Region " Public Methods "

        Public Sub RecolorEntireText()
            If m_bColorCode Then
                If Not m_rtbControl.Text Is Nothing _
                    OrElse Not m_rtbControl.Text.Length = 0 Then
                    bIsProcessingText = True
                    LockWindow(True)
                    Dim iCurrentPosition As Integer = m_rtbControl.SelectionStart
                    m_rtbControl.SelectionStart = _
                        WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_LINEINDEX, 0, 0)
                    ProcessString(m_rtbControl.Text)
                    WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                        iCurrentPosition, iCurrentPosition)
                    m_rtbControl.SelectionColor = m_ColorSchema.NormalColor
                    m_rtbControl.SelectionFont = m_ColorSchema.NormalFont
                    iPreviousTextLength = m_rtbControl.TextLength
                    LockWindow(False)
                    bIsProcessingText = False
                End If
            End If
        End Sub

        Public Sub UnColorEntireText()
            If Not m_rtbControl.Text Is Nothing _
                OrElse Not m_rtbControl.Text.Length = 0 Then
                bIsProcessingText = True
                LockWindow(True)
                Dim iCurrentPosition As Integer = m_rtbControl.SelectionStart
                WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                    0, m_rtbControl.TextLength)
                m_rtbControl.SelectionColor = m_ColorSchema.NormalColor
                m_rtbControl.SelectionFont = m_ColorSchema.NormalFont
                WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                    iCurrentPosition, iCurrentPosition)
                iPreviousTextLength = m_rtbControl.TextLength
                LockWindow(False)
                bIsProcessingText = False
            End If
        End Sub

#End Region

#Region " Handlers "

        Private Sub m_rtbControl_KeyDown(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.KeyEventArgs) Handles m_rtbControl.KeyDown
            bIsPaste = False
            If e.Control = True Then
                Select Case e.KeyCode
                    Case Keys.V
                        bIsPaste = True
                        iPreviousLineIndex = GetCurrentLineIndex()
                        If m_rtbControl.SelectionLength = m_rtbControl.TextLength Then
                            iPreviousTextLength = 0
                        Else
                            iPreviousTextLength = m_rtbControl.TextLength
                        End If
                End Select
            ElseIf e.Shift = True Then
                Select Case e.KeyCode
                    Case Keys.Insert
                        bIsPaste = True
                        iPreviousLineIndex = GetCurrentLineIndex()
                        If m_rtbControl.SelectionLength = m_rtbControl.TextLength Then
                            iPreviousTextLength = 0
                        Else
                            iPreviousTextLength = m_rtbControl.TextLength
                        End If
                End Select
            End If
        End Sub

        Private Sub m_rtbControl_TextChanged(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles m_rtbControl.TextChanged
            If bIsProcessingText Then Return
            If m_bColorCode Then
                LockWindow(True)
                If m_rtbControl.TextLength = 0 Then
                    iPreviousTextLength = 0
                    WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, 0, -1)
                    WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, 0, 0)
                    WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETCHARFORMAT, _
                        WIN32API.SCF_SELECTION, m_ColorSchema.CharFormatNormalText)
                    Return
                End If
                Dim iCurrentPosition As Integer = m_rtbControl.SelectionStart
                If bIsPaste Then
                    If iPreviousTextLength = 0 Then
                        RecolorEntireText()
                    Else
                        Dim iCurrentLineIndex As Integer = GetCurrentLineIndex()
                        If iPreviousLineIndex = iCurrentLineIndex Then
                            ProcessString(GetCurrentLineString())
                        Else
                            m_rtbControl.SelectionStart = WIN32API.SendMessage( _
                                m_rtbControl.Handle, WIN32API.EM_LINEINDEX, _
                                iPreviousLineIndex, 0)
                            ProcessString( _
                                String.Join(vbLf, _
                                            m_rtbControl.Lines, _
                                            iPreviousLineIndex, _
                                            iCurrentLineIndex - iPreviousLineIndex + 1))
                        End If
                    End If
                Else
                    If iPreviousTextLength = 0 Then
                        RecolorEntireText()
                    Else
                        ProcessString(GetCurrentLineString())
                    End If
                End If
                WIN32API.SendMessage(m_rtbControl.Handle, WIN32API.EM_SETSEL, _
                    iCurrentPosition, iCurrentPosition)
                m_rtbControl.SelectionColor = m_ColorSchema.NormalColor
                m_rtbControl.SelectionFont = m_ColorSchema.NormalFont
                iPreviousTextLength = m_rtbControl.TextLength
                LockWindow(False)
            End If
        End Sub

#End Region

    End Class

    <Serializable()> Public Class clsColorRichTextBoxSchema

#Region " Constructors "

        Public Sub New(ByVal TypeOfColorSchema As enColorSchemaType)
            ColorSchemaType = TypeOfColorSchema
        End Sub

        Public Sub New(ByVal ColorSchema As clsColorRichTextBoxSchema)
            m_aKeywords = ColorSchema.Keywords
            m_sLineComment = ColorSchema.LineComment
            m_cNormalColor = ColorSchema.NormalColor
            m_cKeywordColor = ColorSchema.KeywordColor
            m_cLineCommentColor = ColorSchema.LineCommentColor
            m_cStringColor = ColorSchema.StringColor
            m_fNormalFont = ColorSchema.NormalFont
            m_fKeywordFont = ColorSchema.KeywordFont
            m_fLineCommentFont = ColorSchema.LineCommentFont
            m_fStringFont = ColorSchema.StringFont
            m_bCaseSensitive = ColorSchema.CaseSensitive
            m_bFormatKeyword = ColorSchema.FormatKeyword
            m_ColorSchemaType = ColorSchema.ColorSchemaType
            PrepareSchema()
        End Sub

#End Region

#Region " Private properties "

        Private Const SCHEMA_KEYWORDS_SEPARATOR As String = "|"

#End Region

#Region " Public properties "

        Public Enum enColorSchemaType
            VBNET
            Other
        End Enum

        Private m_aKeywords() As String
        Private m_sLineComment As String
        Private m_cNormalColor As System.Drawing.Color
        Private m_cKeywordColor As System.Drawing.Color
        Private m_cLineCommentColor As System.Drawing.Color
        Private m_cStringColor As System.Drawing.Color
        Private m_fNormalFont As System.Drawing.Font
        Private m_fKeywordFont As System.Drawing.Font
        Private m_fLineCommentFont As System.Drawing.Font
        Private m_fStringFont As System.Drawing.Font
        Private m_bCaseSensitive As Boolean
        Private m_bFormatKeyword As Boolean
        Private m_ColorSchemaType As enColorSchemaType
        <NonSerialized()> Private m_sRegexPatternKeyword As String
        <NonSerialized()> Private m_sRegexPatternLineComment As String
        <NonSerialized()> Private m_sRegexPatternString As String
        <NonSerialized()> Private m_slKeywords As New SortedList()
        <NonSerialized()> Private m_cfNormalText As WIN32API.CHARFORMAT
        <NonSerialized()> Private m_cfKeyword As WIN32API.CHARFORMAT
        <NonSerialized()> Private m_cfLineComment As WIN32API.CHARFORMAT
        <NonSerialized()> Private m_cfString As WIN32API.CHARFORMAT

        Public Property Keywords() As String()
            Get
                Return m_aKeywords
            End Get
            Set(ByVal Value As String())
                m_aKeywords = Value
                PrepareSchema()
            End Set
        End Property

        Public Property LineComment() As String
            Get
                Return m_sLineComment
            End Get
            Set(ByVal Value As String)
                m_sLineComment = Value
                PrepareSchema()
            End Set
        End Property

        Public Property NormalColor() As System.Drawing.Color
            Get
                Return m_cNormalColor
            End Get
            Set(ByVal Value As System.Drawing.Color)
                m_cNormalColor = Value
                PrepareCharFormats(m_cfNormalText, m_fNormalFont, m_cNormalColor)
            End Set
        End Property

        Public Property KeywordColor() As System.Drawing.Color
            Get
                Return m_cKeywordColor
            End Get
            Set(ByVal Value As System.Drawing.Color)
                m_cKeywordColor = Value
                PrepareCharFormats(m_cfKeyword, m_fKeywordFont, m_cKeywordColor)
            End Set
        End Property

        Public Property LineCommentColor() As System.Drawing.Color
            Get
                Return m_cLineCommentColor
            End Get
            Set(ByVal Value As System.Drawing.Color)
                m_cLineCommentColor = Value
                PrepareCharFormats(m_cfLineComment, _
                    m_fLineCommentFont, m_cLineCommentColor)
            End Set
        End Property

        Public Property StringColor() As System.Drawing.Color
            Get
                Return m_cStringColor
            End Get
            Set(ByVal Value As System.Drawing.Color)
                m_cStringColor = Value
                PrepareCharFormats(m_cfString, m_fStringFont, m_cStringColor)
            End Set
        End Property

        Public Property NormalFont() As System.Drawing.Font
            Get
                Return m_fNormalFont
            End Get
            Set(ByVal Value As System.Drawing.Font)
                m_fNormalFont = Value
                PrepareCharFormats(m_cfNormalText, m_fNormalFont, m_cNormalColor)
            End Set
        End Property

        Public Property KeywordFont() As System.Drawing.Font
            Get
                Return m_fKeywordFont
            End Get
            Set(ByVal Value As System.Drawing.Font)
                m_fKeywordFont = Value
                PrepareCharFormats(m_cfKeyword, m_fKeywordFont, m_cKeywordColor)
            End Set
        End Property

        Public Property LineCommentFont() As System.Drawing.Font
            Get
                Return m_fLineCommentFont
            End Get
            Set(ByVal Value As System.Drawing.Font)
                m_fLineCommentFont = Value
                PrepareCharFormats(m_cfLineComment, _
                    m_fLineCommentFont, m_cLineCommentColor)
            End Set
        End Property

        Public Property StringFont() As System.Drawing.Font
            Get
                Return m_fStringFont
            End Get
            Set(ByVal Value As System.Drawing.Font)
                m_fStringFont = Value
                PrepareCharFormats(m_cfString, m_fStringFont, m_cStringColor)
            End Set
        End Property

        Public Property CaseSensitive() As Boolean
            Get
                Return m_bCaseSensitive
            End Get
            Set(ByVal Value As Boolean)
                m_bCaseSensitive = Value
            End Set
        End Property

        Public Property FormatKeyword() As Boolean
            Get
                Return m_bFormatKeyword
            End Get
            Set(ByVal Value As Boolean)
                m_bFormatKeyword = Value
            End Set
        End Property

        Public Property ColorSchemaType() As enColorSchemaType
            Get
                Return m_ColorSchemaType
            End Get
            Set(ByVal Value As enColorSchemaType)
                m_ColorSchemaType = Value
                ChangeSchema(Value)
            End Set
        End Property

        Public ReadOnly Property RegexPatternKeyword() As String
            Get
                Return m_sRegexPatternKeyword
            End Get
        End Property

        Public ReadOnly Property RegexPatternLineComment() As String
            Get
                Return m_sRegexPatternLineComment
            End Get
        End Property

        Public ReadOnly Property RegexPatternString() As String
            Get
                Return m_sRegexPatternString
            End Get
        End Property

        Public ReadOnly Property slKeywords() As SortedList
            Get
                Return m_slKeywords
            End Get
        End Property

        Public ReadOnly Property CharFormatNormalText() As WIN32API.CHARFORMAT
            Get
                Return m_cfNormalText
            End Get
        End Property

        Public ReadOnly Property CharFormatKeyword() As WIN32API.CHARFORMAT
            Get
                Return m_cfKeyword
            End Get
        End Property

        Public ReadOnly Property CharFormatLineComment() As WIN32API.CHARFORMAT
            Get
                Return m_cfLineComment
            End Get
        End Property

        Public ReadOnly Property CharFormatString() As WIN32API.CHARFORMAT
            Get
                Return m_cfString
            End Get
        End Property

#End Region

#Region " Private methods "

        Private Sub ChangeSchema(ByVal SchemaType As enColorSchemaType)
            Select Case SchemaType
                Case ColorSchemaType.VBNET
                    m_aKeywords = "Addhandler,AddressOf,Alias,And,AndAlso,Ansi,As,Assembly,Auto,Boolean,ByRef,Byte,ByVal,Call,Case,Catch,CBool,CByte,CChar,CDate,CDbl,CDec,Char,CInt,Class,CLng,CObj,Const,CShort,CSng,CStr,CType,Date,Decimal,Declare,Default,Delegate,Dim,DirectCast,Do,Double,Each,Else,ElseIf,End,EndIf,Enum,Erase,Error,Event,Exit,Explicit,ExternalSource,False,Finally,For,Friend,Function,Get,GetType,GoTo,Handles,If,Implements,Imports,In,Inherits,Integer,Interface,Is,Lib,Like,Long,Loop,Me,Mod,Module,MustInherit,MustOverride,MyBase,MyClass,Namespace,New,Next,Not,Nothing,NotInheritable,NotOverridable,Object,Off,On,Option,Option Compare Binary,Option Compare Text,Optional,Or,OrElse,Overloads,Overridable,Overrides,ParamArray,Preserve,Private,Property,Protected,Public,RaiseEvent,ReadOnly,ReDim,Region,RemoveHandler,Resume,Return,Select,Set,Shadows,Shared,Short,Single,Static,Step,Stop,Strict,String,Structure,Sub,SyncLock,Then,Throw,To,True,Try,TypeOf,Unicode,Until,When,While,With,WithEvents,WriteOnly,Xor".Split(","c)
                    m_sLineComment = "'"
                    m_bCaseSensitive = False
                    m_bFormatKeyword = True
                Case ColorSchemaType.Other
                    m_aKeywords = CType( _
                        Array.CreateInstance(GetType( _
                                System.String), 0), String())
                    m_sLineComment = String.Empty
                    m_bCaseSensitive = False
                    m_bFormatKeyword = False
            End Select
            m_cNormalColor = System.Drawing.Color.Black
            m_cKeywordColor = System.Drawing.Color.Blue
            m_cLineCommentColor = System.Drawing.Color.Green
            m_cStringColor = System.Drawing.Color.Purple
            m_fNormalFont = New System.Drawing.Font( _
                New Drawing.FontFamily("Courier New"), 10, _
                FontStyle.Regular)
            m_fKeywordFont = New System.Drawing.Font( _
                New Drawing.FontFamily("Courier New"), 10, _
                FontStyle.Regular)
            m_fLineCommentFont = New System.Drawing.Font( _
                New Drawing.FontFamily("Courier New"), 10, _
                FontStyle.Regular Or FontStyle.Italic)
            m_fStringFont = New System.Drawing.Font( _
                New Drawing.FontFamily("Courier New"), 10, _
                FontStyle.Regular)
            PrepareSchema()
        End Sub

        Private Sub PrepareSchema()
            m_sRegexPatternKeyword = String.Empty
            m_sRegexPatternLineComment = String.Empty
            m_sRegexPatternString = String.Empty
            If Not m_aKeywords Is Nothing _
                AndAlso Not m_aKeywords.Length = 0 Then
                m_slKeywords = New SortedList()
                Dim iCount As Integer
                For iCount = 0 To m_aKeywords.Length - 1
                    m_sRegexPatternKeyword &= _
                    ChangeSystemSymbols(m_aKeywords(iCount)) _
                    & SCHEMA_KEYWORDS_SEPARATOR
                    m_slKeywords.Add(m_aKeywords(iCount).ToLower, m_aKeywords(iCount))
                Next iCount
                m_sRegexPatternKeyword = m_sRegexPatternKeyword.Substring(0, _
                    m_sRegexPatternKeyword.Length - SCHEMA_KEYWORDS_SEPARATOR.Length)
                If Not m_sRegexPatternKeyword = String.Empty Then
                    m_sRegexPatternKeyword = "\b(" & m_sRegexPatternKeyword & ")\b"
                End If
            End If
            If Not m_sLineComment = String.Empty Then
                m_sRegexPatternLineComment = ChangeSystemSymbols(m_sLineComment) & "(.*?)(\n|$)"
            End If
            m_sRegexPatternString = """(.*?)(""|\n|$)"
            PrepareCharFormats(m_cfNormalText, m_fNormalFont, m_cNormalColor)
            PrepareCharFormats(m_cfLineComment, m_fLineCommentFont, m_cLineCommentColor)
            PrepareCharFormats(m_cfKeyword, m_fKeywordFont, m_cKeywordColor)
            PrepareCharFormats(m_cfString, m_fStringFont, m_cStringColor)
        End Sub

        Private Sub PrepareCharFormats(ByRef CharFormat As WIN32API.CHARFORMAT, _
            ByVal CharFormatFont As System.Drawing.Font, _
            ByVal CharFormatColor As System.Drawing.Color)
            CharFormat = New WIN32API.CHARFORMAT()
            CharFormat.cbSize = Marshal.SizeOf(GetType(WIN32API.CHARFORMAT))
            CharFormat.dwMask = WIN32API.CFM_BOLD Or WIN32API.CFM_COLOR Or _
                WIN32API.CFM_FACE Or WIN32API.CFM_ITALIC Or _
                WIN32API.CFM_SIZE Or WIN32API.CFM_STRIKEOUT Or _
                WIN32API.CFM_UNDERLINE
            If CharFormatFont.Bold Then CharFormat.dwEffects = _
                WIN32API.CFE_BOLD
            If CharFormatFont.Italic Then CharFormat.dwEffects = _
                CharFormat.dwEffects Or WIN32API.CFE_ITALIC
            If CharFormatFont.Strikeout Then CharFormat.dwEffects = _
                CharFormat.dwEffects Or WIN32API.CFE_STRIKEOUT
            If CharFormatFont.Underline Then CharFormat.dwEffects = _
                CharFormat.dwEffects Or WIN32API.CFE_UNDERLINE
            CharFormat.yHeight = CInt((CharFormatFont.Size * 20))
            CharFormat.szFaceName = CharFormatFont.Name
            CharFormat.crTextColor = _
                System.Drawing.Color.FromArgb( _
                    0, CharFormatColor.B, CharFormatColor.G, CharFormatColor.R).ToArgb
        End Sub

        Private Function ChangeSystemSymbols(ByVal sString As String) As String
            sString = sString.Replace("\", "\\")
            sString = sString.Replace("/", "\/")
            sString = sString.Replace("*", "\*")
            sString = sString.Replace("^", "\^")
            sString = sString.Replace("+", "\+")
            sString = sString.Replace("?", "\?")
            sString = sString.Replace("[", "\[")
            sString = sString.Replace("]", "\]")
            sString = sString.Replace("{", "\{")
            sString = sString.Replace("}", "\}")
            sString = sString.Replace(".", "\.")
            sString = sString.Replace("|", "\|")
            Return sString
        End Function

#End Region

#Region " Public methods "

        Public Overloads Sub SaveSchema(ByVal FileName As String)
            SaveSchema(FileName, Me)
        End Sub

        Public Overloads Sub SaveSchema(ByVal FileName As String, _
            ByVal Schema As clsColorRichTextBoxSchema)
            Try
                Dim stream As IO.Stream = _
                    IO.File.Open(FileName, IO.FileMode.Create)
                Dim formatter As New BinaryFormatter()
                formatter.Serialize(stream, Schema)
                stream.Close()
            Catch
            End Try
        End Sub

        Public Function LoadSchema(ByVal FileName As String) As clsColorRichTextBoxSchema
            Try
                Dim stream As IO.Stream = IO.File.Open(FileName, IO.FileMode.Open)
                Dim formatter As New BinaryFormatter()
                Dim RetVal As clsColorRichTextBoxSchema = _
                    CType(formatter.Deserialize(stream), clsColorRichTextBoxSchema)
                stream.Close()
                Return RetVal
            Catch
                Return Nothing
            End Try
        End Function

#End Region

    End Class

End Namespace

Regards,

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Public Class frmMain
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents rtbMain As System.Windows.Forms.RichTextBox
    Friend WithEvents cmdExit As System.Windows.Forms.Button
    Friend WithEvents cmdLoadFile As System.Windows.Forms.Button
    Friend WithEvents cmdUncolor As System.Windows.Forms.Button
    Friend WithEvents lblTime As System.Windows.Forms.Label
    Friend WithEvents cmdColorCode As System.Windows.Forms.Button
    Friend WithEvents cmdSchema As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.rtbMain = New System.Windows.Forms.RichTextBox()
        Me.cmdExit = New System.Windows.Forms.Button()
        Me.cmdColorCode = New System.Windows.Forms.Button()
        Me.cmdLoadFile = New System.Windows.Forms.Button()
        Me.cmdUncolor = New System.Windows.Forms.Button()
        Me.lblTime = New System.Windows.Forms.Label()
        Me.cmdSchema = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'rtbMain
        '
        Me.rtbMain.AcceptsTab = True
        Me.rtbMain.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.rtbMain.Location = New System.Drawing.Point(7, 7)
        Me.rtbMain.Name = "rtbMain"
        Me.rtbMain.Size = New System.Drawing.Size(833, 563)
        Me.rtbMain.TabIndex = 0
        Me.rtbMain.Text = ""
        Me.rtbMain.WordWrap = False
        '
        'cmdExit
        '
        Me.cmdExit.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.cmdExit.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdExit.Location = New System.Drawing.Point(712, 579)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(128, 23)
        Me.cmdExit.TabIndex = 6
        Me.cmdExit.Text = "E&xit"
        '
        'cmdColorCode
        '
        Me.cmdColorCode.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.cmdColorCode.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdColorCode.Location = New System.Drawing.Point(304, 579)
        Me.cmdColorCode.Name = "cmdColorCode"
        Me.cmdColorCode.Size = New System.Drawing.Size(128, 23)
        Me.cmdColorCode.TabIndex = 3
        Me.cmdColorCode.Text = "&Color Code"
        '
        'cmdLoadFile
        '
        Me.cmdLoadFile.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.cmdLoadFile.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdLoadFile.Location = New System.Drawing.Point(168, 579)
        Me.cmdLoadFile.Name = "cmdLoadFile"
        Me.cmdLoadFile.Size = New System.Drawing.Size(128, 23)
        Me.cmdLoadFile.TabIndex = 2
        Me.cmdLoadFile.Text = "&Load File"
        '
        'cmdUncolor
        '
        Me.cmdUncolor.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.cmdUncolor.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdUncolor.Location = New System.Drawing.Point(440, 579)
        Me.cmdUncolor.Name = "cmdUncolor"
        Me.cmdUncolor.Size = New System.Drawing.Size(127, 23)
        Me.cmdUncolor.TabIndex = 4
        Me.cmdUncolor.Text = "&Stop color"
        '
        'lblTime
        '
        Me.lblTime.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.lblTime.Location = New System.Drawing.Point(8, 581)
        Me.lblTime.Name = "lblTime"
        Me.lblTime.Size = New System.Drawing.Size(154, 16)
        Me.lblTime.TabIndex = 1
        '
        'cmdSchema
        '
        Me.cmdSchema.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.cmdSchema.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdSchema.Location = New System.Drawing.Point(576, 579)
        Me.cmdSchema.Name = "cmdSchema"
        Me.cmdSchema.Size = New System.Drawing.Size(128, 23)
        Me.cmdSchema.TabIndex = 5
        Me.cmdSchema.Text = "&Edit Schema"
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.cmdExit
        Me.ClientSize = New System.Drawing.Size(848, 610)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdSchema, Me.lblTime, Me.cmdUncolor, Me.cmdLoadFile, Me.cmdColorCode, Me.cmdExit, Me.rtbMain})
        Me.Name = "frmMain"
        Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Color Rich Text Box Demo ((c) RoKo, 2003, bigroko@mail.ru)"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private m_ColorRTB As ColorRichTextBox.clsColorRichTextBox

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        m_ColorRTB = New ColorRichTextBox.clsColorRichTextBox(rtbMain)
    End Sub

    Private Sub cmdLoadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoadFile.Click
        Dim ofd As New OpenFileDialog()
        ofd.InitialDirectory = IO.Directory.GetCurrentDirectory
        ofd.Filter = "VB.NET files (*.vb)|*.vb"
        If ofd.ShowDialog = DialogResult.OK Then
            Dim sr As New IO.StreamReader(ofd.FileName)
            m_ColorRTB.ColorCode = False
            rtbMain.Text = sr.ReadToEnd
            m_ColorRTB.ColorCode = True
            Dim StartTime As Long = Now.Ticks
            m_ColorRTB.RecolorEntireText()
            Dim ts As New TimeSpan(Now.Ticks - StartTime)
            lblTime.Text = "Load File: " & ts.TotalMilliseconds / 1000 & " sec."
            sr.Close()
        End If
    End Sub

    Private Sub cmdColorCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColorCode.Click
        m_ColorRTB.ColorCode = True
        Dim StartTime As Long = Now.Ticks
        m_ColorRTB.RecolorEntireText()
        Dim ts As New TimeSpan(Now.Ticks - StartTime)
        lblTime.Text = "Color Code: " & ts.TotalMilliseconds / 1000 & " sec."
    End Sub

    Private Sub cmdUncolor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUncolor.Click
        Dim StartTime As Long = Now.Ticks
        m_ColorRTB.ColorCode = False
        Dim ts As New TimeSpan(Now.Ticks - StartTime)
        lblTime.Text = "Stop Color: " & ts.TotalMilliseconds / 1000 & " sec."
    End Sub

    Private Sub cmdSchema_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSchema.Click
        Dim SchemaDlg As New frmSchema(m_ColorRTB.ColorSchema)
        SchemaDlg.ShowDialog()
        m_ColorRTB.ColorSchema = New ColorRichTextBox.clsColorRichTextBoxSchema(SchemaDlg.m_Schema)
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Close()
    End Sub

End Class
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
0
 
LVL 8

Author Comment

by:razo
Comment Utility
how would i use this?
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
AeroSaga:

That's for Windows Forms, not ASP.NET isn't it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
you could use the same class for asp.net/vb.net, just include a reference to the class in your project.

Regards,

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Look at the link I sent you its catagory is ASP.NET/VB.NET, download from them and you get a bunch of documentation as well
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
Have you actually tried this on an ASP.NET page? The code you supplied is definitely for a Windows App and uses controls that aren't available in ASP.NET
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
not the seperate class, just download the sample and RTFM
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
if that one seems to hard for you how bout this one:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1636&lngWId=10

Regards,

Aeros
0
 
LVL 8

Author Comment

by:razo
Comment Utility
does this control provide the functionality for removing all toolbars? for defining the color programatically? and for outputting text while ignoring the format
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Title: ASP .NET (VB) Rich Text Box
Description: This is a Rich Text Box for ASP .NET. You can copy information from a word document into it and it will keep the format and save it to a database for display on the web. This is built into VB .NET but there is nothing out there for ASP .NET. After doing some searching and comming up with nothing we decided to make our own and share it with everyone.
You can also format the text with the controls built into the Rich Text box. Example Bold, Underline, Change the color, center, etc.

This file came from Planet-Source-Code.com...the home millions of lines of source code
You can view comments on this code/and or vote on it at: http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1636&lngWId=10

The author may have retained certain copyrights to this code...please observe their request and the law by reviewing all copyright conditions at the above URL.

0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Have you considered using dotnetnuke, it has such functionality prebuilt.

http://www.dotnetnuke.com/

Regards,

Aeros
0
 
LVL 8

Author Comment

by:razo
Comment Utility
plz stop sending me links
i dont have time to check them all
i have specified what i exactly need if any of these controls support such requirements i prefer to check the one u recommend
0
 
LVL 9

Expert Comment

by:crescendo
Comment Utility
razo:

I don't think you're going to find what you described in a single control. How about an alternative way to achieve your aim? You could use a label control to display the formatted text, then have an "Edit" button, which makes the label invisible, and a textbox with the plain text visible in its place. The user edits the plain text. How does that sound?
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
If you don't have time then neither do I....Lata
0
 
LVL 8

Author Comment

by:razo
Comment Utility
the whole point of adding color is to make it easy for users to format
so sorry ur suggestion doesnt work
0
 
LVL 9

Accepted Solution

by:
crescendo earned 500 total points
Comment Utility
OK, well here's the bit oif code you asked for, to strip tags. Just call it something like

    sPlainText = StripTags(FreetextBox1.Text)

Hope things work out for you.

- crescendo

    Private Function StripTags(ByVal sText As String) As String
        Dim bOK As Boolean = False
        Dim nStart As Integer
        Dim nEnd As Integer

        Do
            nStart = InStr(sText, "<", CompareMethod.Text)
            If nStart = 0 Then Exit Do

            nEnd = InStr(nStart, sText, ">", CompareMethod.Text)
            If nEnd = 0 Then nEnd = Len(sText)

            ' Remove from "<" to ">"
            sText = sText.Remove(nStart - 1, nEnd - nStart + 1)
        Loop While InStr(sText, "<", CompareMethod.Text) > 0

        Return sText

    End Function
0
 
LVL 8

Author Comment

by:razo
Comment Utility
ok thanks for this code
let me explain to u why i need the coloring
i have this xml file and i want to display in a textbox for editing i want to color elements and attributes so it is easy to find them
obviously i dont want the coloring to be saved later with the xml file
can u help me?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now