in userconrtrol i named doColour... but also i added method called
doColor....please have a look .....
in usercontrol......:
Option Explicit On
Option Strict Off
Imports System.Runtime.InteropServices
Imports System.Drawing
Namespace PirateChat
<System.ComponentModel.DesignerCategoryAttribute("UserControl")> _
Public Class RichTextBox
Inherits System.Windows.Forms.RichTextBox
Private Declare Function GetScrollRange Lib "User32" (ByVal hWnd
As IntPtr, ByVal nBar As Integer, ByRef lpMinPos As Integer, ByRef
lpMaxPos As Integer) As Boolean
Function doColor(ByVal a As String)
Dim b As String, n, fgcolor, bgcolor As Integer
Dim colour() As Color = {Color.White, Color.Black,
Color.DarkBlue, Color.DarkGreen, Color.Red, Color.Brown, _
Color.Purple, Color.Orange,
Color.Yellow, Color.LightGreen, Color.DarkMagenta, Color.SkyBlue, _
Color.Blue, Color.Magenta,
Color.Gray, Color.LightSlateGray}
Dim rtb As RichTextBox
rtb = New RichTextBox
fgcolor = 1
bgcolor = 0
For n = 1 To a.Length
b = Mid(a, n, 1)
If b = Chr(3) Then
'Parse Colours
If IsNumeric(Mid(a, n + 1, 1)) Then
If IsNumeric(Mid(a, n + 2, 1)) Then
If Mid(a, n + 3, 1) = "," Then
If IsNumeric(Mid(a, n + 4, 1)) Then
If IsNumeric(Mid(a, n + 5, 1)) Then
'@##,##
fgcolor = CInt(Mid(a, n + 1, 2))
bgcolor = CInt(Mid(a, n + 4, 2))
n += 5
Else
'@##,#
fgcolor = CInt(Mid(a, n + 1, 2))
bgcolor = CInt(Mid(a, n + 4, 1))
n += 4
End If
Else
'@##,
fgcolor = CInt(Mid(a, n + 1, 2))
n += 3
End If
Else
'@##
fgcolor = CInt(Mid(a, n + 1, 2))
n += 2
End If
ElseIf Mid(a, n + 2, 1) = "," Then
If IsNumeric(Mid(a, n + 3, 1)) Then
If IsNumeric(Mid(a, n + 4, 1)) Then
'@#,##
fgcolor = CInt(Mid(a, n + 1, 1))
bgcolor = CInt(Mid(a, n + 3, 2))
n += 4
Else
'@#,#
fgcolor = CInt(Mid(a, n + 1, 1))
bgcolor = CInt(Mid(a, n + 3, 1))
n += 3
End If
Else
'@#,
fgcolor = CInt(Mid(a, n + 1, 1))
n += 2
End If
Else
'@#
fgcolor = CInt(Mid(a, n + 1, 1))
n = n + 1
End If
If fgcolor > 15 Then
fgcolor = 1
End If
If bgcolor > 15 Then
bgcolor = 0
End If
rtb.SelectionColor = colour(fgcolor)
SelectionBackColor = colour(bgcolor)
Else
rtb.SelectionColor = colour(1)
SelectionBackColor = colour(0)
End If
ElseIf b = Chr(2) Then
Dim IsBold As Boolean = ((rtb.SelectionFont.Style
And FontStyle.Bold) = FontStyle.Bold)
rtb.SelectionFont = _
New Font(rtb.SelectionFont,
DirectCast(IIf(IsBold, rtb.SelectionFont.Style And Not FontStyle.Bold,
rtb.SelectionFont.Style Or FontStyle.Bold), FontStyle))
ElseIf b = Chr(31) Then
Dim IsUnderline As Boolean =
((rtb.SelectionFont.Style And FontStyle.Underline) = FontStyle.Underline)
rtb.SelectionFont = _
New Font( _
rtb.SelectionFont, _
DirectCast(IIf(IsUnderline,
rtb.SelectionFont.Style And Not FontStyle.Underline,
rtb.SelectionFont.Style Or FontStyle.Underline), FontStyle))
ElseIf b = Chr(22) Then
Dim IsItalic As Boolean = ((rtb.SelectionFont.Style
And FontStyle.Italic) = FontStyle.Italic)
rtb.SelectionFont = _
New Font( _
rtb.SelectionFont, _
DirectCast(IIf(IsItalic,
rtb.SelectionFont.Style And Not FontStyle.Italic,
rtb.SelectionFont.Style Or FontStyle.Italic), FontStyle))
ElseIf b = "" Then
b = Mid(a, n, 1)
Else
' rtb.SelectedText = DirectCast(b.ToString, String)
' rtb.SelectedText = CType(b, String) '.ToString
rtb.SelectedText = b.ToString
End If
Next n
End Function
ne hints u cann help me?
regsrds,