Imports System.Text
Public Class RichTextEditor
    Inherits System.Windows.Forms.UserControl

#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
        Application.EnableVisualStyles()
    End Sub

    'UserControl 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 panSize As System.Windows.Forms.Panel
    Friend WithEvents lstSize As System.Windows.Forms.ListBox
    Friend WithEvents panFont As System.Windows.Forms.Panel
    Friend WithEvents lstFonts As System.Windows.Forms.ListBox
    Friend WithEvents panColors As System.Windows.Forms.Panel
    Friend WithEvents PictureBox36 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox37 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox38 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox39 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox40 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox26 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox27 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox28 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox29 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox31 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox32 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox33 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox34 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox21 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox22 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox23 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox24 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox16 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox17 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox18 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox19 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox13 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox14 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox15 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox10 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox11 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox12 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox7 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox8 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox9 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox4 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox5 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox6 As System.Windows.Forms.PictureBox
    Friend WithEvents cmdOther As System.Windows.Forms.Button
    Friend WithEvents cmdRight As System.Windows.Forms.Button
    Friend WithEvents cmdCenter As System.Windows.Forms.Button
    Friend WithEvents cdmLeft As System.Windows.Forms.Button
    Friend WithEvents cmdSize As System.Windows.Forms.Button
    Friend WithEvents cmdFont As System.Windows.Forms.Button
    Friend WithEvents cmdColor As System.Windows.Forms.Button
    Friend WithEvents cmdUnderline As System.Windows.Forms.Button
    Friend WithEvents cmdItalics As System.Windows.Forms.Button
    Friend WithEvents cmdBold As System.Windows.Forms.Button
    Friend WithEvents rtbText As System.Windows.Forms.RichTextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.panSize = New System.Windows.Forms.Panel
        Me.lstSize = New System.Windows.Forms.ListBox
        Me.panFont = New System.Windows.Forms.Panel
        Me.lstFonts = New System.Windows.Forms.ListBox
        Me.panColors = New System.Windows.Forms.Panel
        Me.PictureBox36 = New System.Windows.Forms.PictureBox
        Me.PictureBox37 = New System.Windows.Forms.PictureBox
        Me.PictureBox38 = New System.Windows.Forms.PictureBox
        Me.PictureBox39 = New System.Windows.Forms.PictureBox
        Me.PictureBox40 = New System.Windows.Forms.PictureBox
        Me.PictureBox26 = New System.Windows.Forms.PictureBox
        Me.PictureBox27 = New System.Windows.Forms.PictureBox
        Me.PictureBox28 = New System.Windows.Forms.PictureBox
        Me.PictureBox29 = New System.Windows.Forms.PictureBox
        Me.PictureBox31 = New System.Windows.Forms.PictureBox
        Me.PictureBox32 = New System.Windows.Forms.PictureBox
        Me.PictureBox33 = New System.Windows.Forms.PictureBox
        Me.PictureBox34 = New System.Windows.Forms.PictureBox
        Me.PictureBox21 = New System.Windows.Forms.PictureBox
        Me.PictureBox22 = New System.Windows.Forms.PictureBox
        Me.PictureBox23 = New System.Windows.Forms.PictureBox
        Me.PictureBox24 = New System.Windows.Forms.PictureBox
        Me.PictureBox16 = New System.Windows.Forms.PictureBox
        Me.PictureBox17 = New System.Windows.Forms.PictureBox
        Me.PictureBox18 = New System.Windows.Forms.PictureBox
        Me.PictureBox19 = New System.Windows.Forms.PictureBox
        Me.PictureBox13 = New System.Windows.Forms.PictureBox
        Me.PictureBox14 = New System.Windows.Forms.PictureBox
        Me.PictureBox15 = New System.Windows.Forms.PictureBox
        Me.PictureBox10 = New System.Windows.Forms.PictureBox
        Me.PictureBox11 = New System.Windows.Forms.PictureBox
        Me.PictureBox12 = New System.Windows.Forms.PictureBox
        Me.PictureBox7 = New System.Windows.Forms.PictureBox
        Me.PictureBox8 = New System.Windows.Forms.PictureBox
        Me.PictureBox9 = New System.Windows.Forms.PictureBox
        Me.PictureBox4 = New System.Windows.Forms.PictureBox
        Me.PictureBox5 = New System.Windows.Forms.PictureBox
        Me.PictureBox6 = New System.Windows.Forms.PictureBox
        Me.cmdOther = New System.Windows.Forms.Button
        Me.cmdRight = New System.Windows.Forms.Button
        Me.cmdCenter = New System.Windows.Forms.Button
        Me.cdmLeft = New System.Windows.Forms.Button
        Me.cmdSize = New System.Windows.Forms.Button
        Me.cmdFont = New System.Windows.Forms.Button
        Me.cmdColor = New System.Windows.Forms.Button
        Me.cmdUnderline = New System.Windows.Forms.Button
        Me.cmdItalics = New System.Windows.Forms.Button
        Me.cmdBold = New System.Windows.Forms.Button
        Me.rtbText = New System.Windows.Forms.RichTextBox
        Me.panSize.SuspendLayout()
        Me.panFont.SuspendLayout()
        Me.panColors.SuspendLayout()
        Me.SuspendLayout()
        '
        'panSize
        '
        Me.panSize.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.panSize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.panSize.Controls.Add(Me.lstSize)
        Me.panSize.Location = New System.Drawing.Point(88, 24)
        Me.panSize.Name = "panSize"
        Me.panSize.Size = New System.Drawing.Size(48, 148)
        Me.panSize.TabIndex = 79
        Me.panSize.Visible = False
        '
        'lstSize
        '
        Me.lstSize.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lstSize.Items.AddRange(New Object() {"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"})
        Me.lstSize.Location = New System.Drawing.Point(0, 0)
        Me.lstSize.Name = "lstSize"
        Me.lstSize.Size = New System.Drawing.Size(48, 147)
        Me.lstSize.TabIndex = 0
        '
        'panFont
        '
        Me.panFont.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.panFont.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.panFont.Controls.Add(Me.lstFonts)
        Me.panFont.Location = New System.Drawing.Point(88, 24)
        Me.panFont.Name = "panFont"
        Me.panFont.Size = New System.Drawing.Size(144, 148)
        Me.panFont.TabIndex = 78
        Me.panFont.Visible = False
        '
        'lstFonts
        '
        Me.lstFonts.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lstFonts.Items.AddRange(New Object() {"Arial", "Arial Black", "Arial Narrow", "Arial Unicode MS", "AvantGarde Bk BT", "Batang", "Belwe Bd BT", "Book Antiqua", "Bookman Old Style", "Century", "Century Gothic", "Comic Sans MS", "CommercialScript BT", "CopprplGoth BT", "Courier New", "Dauphin", "DomCasual BT", "EngrvrsOldEng BT", "Estrangelo Edessa", "FlamencoD", "Food", "Franklin Gothic Medium", "FrnkGothITC Hv BT", "Garamond", "Gautami", "Georgia", "Haettenschweiler", "Humanst521 Cn BT", "Impact", "Kartika", "Kids", "Latha", "Lithograph", "Lucida Console", "Lucida Sans", "Lucida Sans Unicode", "Mangal", "Map Symbols", "Marlett", "Microsoft Sans Serif", "Monotype Corsiva", "MS Mincho", "MS Outlook", "MT Extra", "Music", "MV Boli", "Palatino Linotype", "Papyrus LET", "PMingLiU", "Raavi", "Shruti", "SimSun", "Sydnie", "Sylfaen", "Symbol", "Tahoma", "Technical", "Times New Roman", "Transportation", "Trebuchet MS", "Tunga", "Verdana", "VisualUI", "Vrinda", "Webdings", "Wingdings", "Wingdings 2", "Wingdings 3"})
        Me.lstFonts.Location = New System.Drawing.Point(0, 0)
        Me.lstFonts.Name = "lstFonts"
        Me.lstFonts.Size = New System.Drawing.Size(144, 147)
        Me.lstFonts.TabIndex = 0
        '
        'panColors
        '
        Me.panColors.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.panColors.Controls.Add(Me.PictureBox36)
        Me.panColors.Controls.Add(Me.PictureBox37)
        Me.panColors.Controls.Add(Me.PictureBox38)
        Me.panColors.Controls.Add(Me.PictureBox39)
        Me.panColors.Controls.Add(Me.PictureBox40)
        Me.panColors.Controls.Add(Me.PictureBox26)
        Me.panColors.Controls.Add(Me.PictureBox27)
        Me.panColors.Controls.Add(Me.PictureBox28)
        Me.panColors.Controls.Add(Me.PictureBox29)
        Me.panColors.Controls.Add(Me.PictureBox31)
        Me.panColors.Controls.Add(Me.PictureBox32)
        Me.panColors.Controls.Add(Me.PictureBox33)
        Me.panColors.Controls.Add(Me.PictureBox34)
        Me.panColors.Controls.Add(Me.PictureBox21)
        Me.panColors.Controls.Add(Me.PictureBox22)
        Me.panColors.Controls.Add(Me.PictureBox23)
        Me.panColors.Controls.Add(Me.PictureBox24)
        Me.panColors.Controls.Add(Me.PictureBox16)
        Me.panColors.Controls.Add(Me.PictureBox17)
        Me.panColors.Controls.Add(Me.PictureBox18)
        Me.panColors.Controls.Add(Me.PictureBox19)
        Me.panColors.Controls.Add(Me.PictureBox13)
        Me.panColors.Controls.Add(Me.PictureBox14)
        Me.panColors.Controls.Add(Me.PictureBox15)
        Me.panColors.Controls.Add(Me.PictureBox10)
        Me.panColors.Controls.Add(Me.PictureBox11)
        Me.panColors.Controls.Add(Me.PictureBox12)
        Me.panColors.Controls.Add(Me.PictureBox7)
        Me.panColors.Controls.Add(Me.PictureBox8)
        Me.panColors.Controls.Add(Me.PictureBox9)
        Me.panColors.Controls.Add(Me.PictureBox4)
        Me.panColors.Controls.Add(Me.PictureBox5)
        Me.panColors.Controls.Add(Me.PictureBox6)
        Me.panColors.Controls.Add(Me.cmdOther)
        Me.panColors.Location = New System.Drawing.Point(88, 24)
        Me.panColors.Name = "panColors"
        Me.panColors.Size = New System.Drawing.Size(115, 83)
        Me.panColors.TabIndex = 77
        Me.panColors.Visible = False
        '
        'PictureBox36
        '
        Me.PictureBox36.BackColor = System.Drawing.Color.White
        Me.PictureBox36.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox36.Location = New System.Drawing.Point(65, 65)
        Me.PictureBox36.Name = "PictureBox36"
        Me.PictureBox36.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox36.TabIndex = 64
        Me.PictureBox36.TabStop = False
        '
        'PictureBox37
        '
        Me.PictureBox37.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.PictureBox37.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox37.Location = New System.Drawing.Point(49, 65)
        Me.PictureBox37.Name = "PictureBox37"
        Me.PictureBox37.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox37.TabIndex = 63
        Me.PictureBox37.TabStop = False
        '
        'PictureBox38
        '
        Me.PictureBox38.BackColor = System.Drawing.Color.Silver
        Me.PictureBox38.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox38.Location = New System.Drawing.Point(33, 65)
        Me.PictureBox38.Name = "PictureBox38"
        Me.PictureBox38.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox38.TabIndex = 62
        Me.PictureBox38.TabStop = False
        '
        'PictureBox39
        '
        Me.PictureBox39.BackColor = System.Drawing.Color.Gray
        Me.PictureBox39.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox39.Location = New System.Drawing.Point(17, 65)
        Me.PictureBox39.Name = "PictureBox39"
        Me.PictureBox39.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox39.TabIndex = 61
        Me.PictureBox39.TabStop = False
        '
        'PictureBox40
        '
        Me.PictureBox40.BackColor = System.Drawing.Color.Black
        Me.PictureBox40.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox40.Location = New System.Drawing.Point(1, 65)
        Me.PictureBox40.Name = "PictureBox40"
        Me.PictureBox40.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox40.TabIndex = 60
        Me.PictureBox40.TabStop = False
        '
        'PictureBox26
        '
        Me.PictureBox26.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
        Me.PictureBox26.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox26.Location = New System.Drawing.Point(97, 49)
        Me.PictureBox26.Name = "PictureBox26"
        Me.PictureBox26.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox26.TabIndex = 59
        Me.PictureBox26.TabStop = False
        '
        'PictureBox27
        '
        Me.PictureBox27.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(255, Byte))
        Me.PictureBox27.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox27.Location = New System.Drawing.Point(97, 33)
        Me.PictureBox27.Name = "PictureBox27"
        Me.PictureBox27.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox27.TabIndex = 58
        Me.PictureBox27.TabStop = False
        '
        'PictureBox28
        '
        Me.PictureBox28.BackColor = System.Drawing.Color.Magenta
        Me.PictureBox28.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox28.Location = New System.Drawing.Point(97, 17)
        Me.PictureBox28.Name = "PictureBox28"
        Me.PictureBox28.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox28.TabIndex = 57
        Me.PictureBox28.TabStop = False
        '
        'PictureBox29
        '
        Me.PictureBox29.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(0, Byte), CType(192, Byte))
        Me.PictureBox29.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox29.Location = New System.Drawing.Point(97, 1)
        Me.PictureBox29.Name = "PictureBox29"
        Me.PictureBox29.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox29.TabIndex = 56
        Me.PictureBox29.TabStop = False
        '
        'PictureBox31
        '
        Me.PictureBox31.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.PictureBox31.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox31.Location = New System.Drawing.Point(81, 49)
        Me.PictureBox31.Name = "PictureBox31"
        Me.PictureBox31.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox31.TabIndex = 54
        Me.PictureBox31.TabStop = False
        '
        'PictureBox32
        '
        Me.PictureBox32.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte))
        Me.PictureBox32.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox32.Location = New System.Drawing.Point(81, 33)
        Me.PictureBox32.Name = "PictureBox32"
        Me.PictureBox32.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox32.TabIndex = 53
        Me.PictureBox32.TabStop = False
        '
        'PictureBox33
        '
        Me.PictureBox33.BackColor = System.Drawing.Color.Blue
        Me.PictureBox33.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox33.Location = New System.Drawing.Point(81, 17)
        Me.PictureBox33.Name = "PictureBox33"
        Me.PictureBox33.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox33.TabIndex = 52
        Me.PictureBox33.TabStop = False
        '
        'PictureBox34
        '
        Me.PictureBox34.BackColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
        Me.PictureBox34.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox34.Location = New System.Drawing.Point(81, 1)
        Me.PictureBox34.Name = "PictureBox34"
        Me.PictureBox34.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox34.TabIndex = 51
        Me.PictureBox34.TabStop = False
        '
        'PictureBox21
        '
        Me.PictureBox21.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(255, Byte))
        Me.PictureBox21.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox21.Location = New System.Drawing.Point(65, 49)
        Me.PictureBox21.Name = "PictureBox21"
        Me.PictureBox21.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox21.TabIndex = 49
        Me.PictureBox21.TabStop = False
        '
        'PictureBox22
        '
        Me.PictureBox22.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(255, Byte), CType(255, Byte))
        Me.PictureBox22.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox22.Location = New System.Drawing.Point(65, 33)
        Me.PictureBox22.Name = "PictureBox22"
        Me.PictureBox22.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox22.TabIndex = 48
        Me.PictureBox22.TabStop = False
        '
        'PictureBox23
        '
        Me.PictureBox23.BackColor = System.Drawing.Color.Aqua
        Me.PictureBox23.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox23.Location = New System.Drawing.Point(65, 17)
        Me.PictureBox23.Name = "PictureBox23"
        Me.PictureBox23.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox23.TabIndex = 47
        Me.PictureBox23.TabStop = False
        '
        'PictureBox24
        '
        Me.PictureBox24.BackColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(192, Byte), CType(192, Byte))
        Me.PictureBox24.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox24.Location = New System.Drawing.Point(65, 1)
        Me.PictureBox24.Name = "PictureBox24"
        Me.PictureBox24.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox24.TabIndex = 46
        Me.PictureBox24.TabStop = False
        '
        'PictureBox16
        '
        Me.PictureBox16.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(192, Byte))
        Me.PictureBox16.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox16.Location = New System.Drawing.Point(49, 49)
        Me.PictureBox16.Name = "PictureBox16"
        Me.PictureBox16.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox16.TabIndex = 44
        Me.PictureBox16.TabStop = False
        '
        'PictureBox17
        '
        Me.PictureBox17.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(255, Byte), CType(128, Byte))
        Me.PictureBox17.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox17.Location = New System.Drawing.Point(49, 33)
        Me.PictureBox17.Name = "PictureBox17"
        Me.PictureBox17.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox17.TabIndex = 43
        Me.PictureBox17.TabStop = False
        '
        'PictureBox18
        '
        Me.PictureBox18.BackColor = System.Drawing.Color.Lime
        Me.PictureBox18.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox18.Location = New System.Drawing.Point(49, 17)
        Me.PictureBox18.Name = "PictureBox18"
        Me.PictureBox18.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox18.TabIndex = 42
        Me.PictureBox18.TabStop = False
        '
        'PictureBox19
        '
        Me.PictureBox19.BackColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(192, Byte), CType(0, Byte))
        Me.PictureBox19.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox19.Location = New System.Drawing.Point(49, 1)
        Me.PictureBox19.Name = "PictureBox19"
        Me.PictureBox19.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox19.TabIndex = 41
        Me.PictureBox19.TabStop = False
        '
        'PictureBox13
        '
        Me.PictureBox13.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
        Me.PictureBox13.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox13.Location = New System.Drawing.Point(33, 49)
        Me.PictureBox13.Name = "PictureBox13"
        Me.PictureBox13.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox13.TabIndex = 39
        Me.PictureBox13.TabStop = False
        '
        'PictureBox14
        '
        Me.PictureBox14.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(224, Byte), CType(192, Byte))
        Me.PictureBox14.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox14.Location = New System.Drawing.Point(17, 49)
        Me.PictureBox14.Name = "PictureBox14"
        Me.PictureBox14.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox14.TabIndex = 38
        Me.PictureBox14.TabStop = False
        '
        'PictureBox15
        '
        Me.PictureBox15.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(192, Byte))
        Me.PictureBox15.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox15.Location = New System.Drawing.Point(1, 49)
        Me.PictureBox15.Name = "PictureBox15"
        Me.PictureBox15.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox15.TabIndex = 37
        Me.PictureBox15.TabStop = False
        '
        'PictureBox10
        '
        Me.PictureBox10.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(128, Byte))
        Me.PictureBox10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox10.Location = New System.Drawing.Point(33, 33)
        Me.PictureBox10.Name = "PictureBox10"
        Me.PictureBox10.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox10.TabIndex = 36
        Me.PictureBox10.TabStop = False
        '
        'PictureBox11
        '
        Me.PictureBox11.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(128, Byte))
        Me.PictureBox11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox11.Location = New System.Drawing.Point(17, 33)
        Me.PictureBox11.Name = "PictureBox11"
        Me.PictureBox11.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox11.TabIndex = 35
        Me.PictureBox11.TabStop = False
        '
        'PictureBox12
        '
        Me.PictureBox12.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(128, Byte))
        Me.PictureBox12.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox12.Location = New System.Drawing.Point(1, 33)
        Me.PictureBox12.Name = "PictureBox12"
        Me.PictureBox12.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox12.TabIndex = 34
        Me.PictureBox12.TabStop = False
        '
        'PictureBox7
        '
        Me.PictureBox7.BackColor = System.Drawing.Color.Yellow
        Me.PictureBox7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox7.Location = New System.Drawing.Point(33, 17)
        Me.PictureBox7.Name = "PictureBox7"
        Me.PictureBox7.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox7.TabIndex = 33
        Me.PictureBox7.TabStop = False
        '
        'PictureBox8
        '
        Me.PictureBox8.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(0, Byte))
        Me.PictureBox8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox8.Location = New System.Drawing.Point(17, 17)
        Me.PictureBox8.Name = "PictureBox8"
        Me.PictureBox8.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox8.TabIndex = 32
        Me.PictureBox8.TabStop = False
        '
        'PictureBox9
        '
        Me.PictureBox9.BackColor = System.Drawing.Color.Red
        Me.PictureBox9.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox9.Location = New System.Drawing.Point(1, 17)
        Me.PictureBox9.Name = "PictureBox9"
        Me.PictureBox9.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox9.TabIndex = 31
        Me.PictureBox9.TabStop = False
        '
        'PictureBox4
        '
        Me.PictureBox4.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(0, Byte))
        Me.PictureBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox4.Location = New System.Drawing.Point(33, 1)
        Me.PictureBox4.Name = "PictureBox4"
        Me.PictureBox4.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox4.TabIndex = 30
        Me.PictureBox4.TabStop = False
        '
        'PictureBox5
        '
        Me.PictureBox5.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(64, Byte), CType(0, Byte))
        Me.PictureBox5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox5.Location = New System.Drawing.Point(17, 1)
        Me.PictureBox5.Name = "PictureBox5"
        Me.PictureBox5.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox5.TabIndex = 29
        Me.PictureBox5.TabStop = False
        '
        'PictureBox6
        '
        Me.PictureBox6.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(0, Byte), CType(0, Byte))
        Me.PictureBox6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.PictureBox6.Location = New System.Drawing.Point(1, 1)
        Me.PictureBox6.Name = "PictureBox6"
        Me.PictureBox6.Size = New System.Drawing.Size(16, 16)
        Me.PictureBox6.TabIndex = 28
        Me.PictureBox6.TabStop = False
        '
        'cmdOther
        '
        Me.cmdOther.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.cmdOther.Font = New System.Drawing.Font("Arial Narrow", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdOther.Location = New System.Drawing.Point(81, 65)
        Me.cmdOther.Name = "cmdOther"
        Me.cmdOther.Size = New System.Drawing.Size(32, 16)
        Me.cmdOther.TabIndex = 0
        Me.cmdOther.Text = "Other"
        '
        'cmdRight
        '
        Me.cmdRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdRight.Location = New System.Drawing.Point(224, 0)
        Me.cmdRight.Name = "cmdRight"
        Me.cmdRight.Size = New System.Drawing.Size(24, 23)
        Me.cmdRight.TabIndex = 76
        Me.cmdRight.Text = "R"
        '
        'cmdCenter
        '
        Me.cmdCenter.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdCenter.Location = New System.Drawing.Point(200, 0)
        Me.cmdCenter.Name = "cmdCenter"
        Me.cmdCenter.Size = New System.Drawing.Size(24, 23)
        Me.cmdCenter.TabIndex = 75
        Me.cmdCenter.Text = "C"
        '
        'cdmLeft
        '
        Me.cdmLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cdmLeft.Location = New System.Drawing.Point(176, 0)
        Me.cdmLeft.Name = "cdmLeft"
        Me.cdmLeft.Size = New System.Drawing.Size(24, 23)
        Me.cdmLeft.TabIndex = 74
        Me.cdmLeft.Text = "L"
        '
        'cmdSize
        '
        Me.cmdSize.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdSize.Location = New System.Drawing.Point(136, 0)
        Me.cmdSize.Name = "cmdSize"
        Me.cmdSize.Size = New System.Drawing.Size(24, 23)
        Me.cmdSize.TabIndex = 73
        Me.cmdSize.Text = "S"
        '
        'cmdFont
        '
        Me.cmdFont.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdFont.Location = New System.Drawing.Point(112, 0)
        Me.cmdFont.Name = "cmdFont"
        Me.cmdFont.Size = New System.Drawing.Size(24, 23)
        Me.cmdFont.TabIndex = 72
        Me.cmdFont.Text = "F"
        '
        'cmdColor
        '
        Me.cmdColor.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdColor.Location = New System.Drawing.Point(88, 0)
        Me.cmdColor.Name = "cmdColor"
        Me.cmdColor.Size = New System.Drawing.Size(24, 23)
        Me.cmdColor.TabIndex = 71
        Me.cmdColor.Text = "C"
        '
        'cmdUnderline
        '
        Me.cmdUnderline.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdUnderline.Location = New System.Drawing.Point(48, 0)
        Me.cmdUnderline.Name = "cmdUnderline"
        Me.cmdUnderline.Size = New System.Drawing.Size(24, 23)
        Me.cmdUnderline.TabIndex = 70
        Me.cmdUnderline.Text = "U"
        '
        'cmdItalics
        '
        Me.cmdItalics.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdItalics.Location = New System.Drawing.Point(24, 0)
        Me.cmdItalics.Name = "cmdItalics"
        Me.cmdItalics.Size = New System.Drawing.Size(24, 23)
        Me.cmdItalics.TabIndex = 69
        Me.cmdItalics.Text = "I"
        '
        'cmdBold
        '
        Me.cmdBold.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cmdBold.Location = New System.Drawing.Point(0, 0)
        Me.cmdBold.Name = "cmdBold"
        Me.cmdBold.Size = New System.Drawing.Size(24, 23)
        Me.cmdBold.TabIndex = 68
        Me.cmdBold.Text = "B"
        '
        'rtbText
        '
        Me.rtbText.AcceptsTab = True
        Me.rtbText.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.rtbText.DetectUrls = False
        Me.rtbText.HideSelection = False
        Me.rtbText.Location = New System.Drawing.Point(0, 24)
        Me.rtbText.Name = "rtbText"
        Me.rtbText.Size = New System.Drawing.Size(272, 160)
        Me.rtbText.TabIndex = 67
        Me.rtbText.Text = ""
        '
        'RichTextEditor
        '
        Me.Controls.Add(Me.panColors)
        Me.Controls.Add(Me.panSize)
        Me.Controls.Add(Me.panFont)
        Me.Controls.Add(Me.cmdRight)
        Me.Controls.Add(Me.cmdCenter)
        Me.Controls.Add(Me.cdmLeft)
        Me.Controls.Add(Me.cmdSize)
        Me.Controls.Add(Me.cmdFont)
        Me.Controls.Add(Me.cmdColor)
        Me.Controls.Add(Me.cmdUnderline)
        Me.Controls.Add(Me.cmdItalics)
        Me.Controls.Add(Me.cmdBold)
        Me.Controls.Add(Me.rtbText)
        Me.Name = "RichTextEditor"
        Me.Size = New System.Drawing.Size(272, 184)
        Me.panSize.ResumeLayout(False)
        Me.panFont.ResumeLayout(False)
        Me.panColors.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBold.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False

        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop

            If rtbText.SelectionFont.Bold = True Then
                If rtbText.SelectionFont.Underline = True And rtbText.SelectionFont.Italic = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline Or FontStyle.Italic)
                ElseIf rtbText.SelectionFont.Underline = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline)
                ElseIf rtbText.SelectionFont.Italic = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic)
                Else
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Regular)
                End If
            Else
                If rtbText.SelectionFont.Underline = True And rtbText.SelectionFont.Italic = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Bold Or FontStyle.Underline Or FontStyle.Italic)
                ElseIf rtbText.SelectionFont.Underline = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Bold Or FontStyle.Underline)
                ElseIf rtbText.SelectionFont.Italic = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Bold Or FontStyle.Italic)
                Else
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Bold)
                End If
            End If

            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght
    End Sub

    Private Sub cmdItalics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdItalics.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False

        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop

            If rtbText.SelectionFont.Italic = True Then
                If rtbText.SelectionFont.Underline = True And rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline Or FontStyle.Bold)
                ElseIf rtbText.SelectionFont.Underline = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline)
                ElseIf rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Bold)
                Else
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Regular)
                End If
            Else
                If rtbText.SelectionFont.Underline = True And rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic Or FontStyle.Underline Or FontStyle.Bold)
                ElseIf rtbText.SelectionFont.Underline = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic Or FontStyle.Underline)
                ElseIf rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic Or FontStyle.Bold)
                Else
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic)
                End If
            End If
            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght
    End Sub

    Private Sub cmdUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUnderline.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False

        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop

            If rtbText.SelectionFont.Underline = True Then
                If rtbText.SelectionFont.Italic = True And rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic Or FontStyle.Bold)
                ElseIf rtbText.SelectionFont.Italic = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Italic)
                ElseIf rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Bold)
                Else
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Regular)
                End If
            Else
                If rtbText.SelectionFont.Italic = True And rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline Or FontStyle.Italic Or FontStyle.Bold)
                ElseIf rtbText.SelectionFont.Italic = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline Or FontStyle.Italic)
                ElseIf rtbText.SelectionFont.Bold = True Then
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline Or FontStyle.Bold)
                Else
                    rtbText.SelectionFont = New Font(rtbText.SelectionFont(), FontStyle.Underline)
                End If
            End If
            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght
    End Sub

    Private Sub rtbText_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbText.TextChanged
        If Not rtbText.SelectionFont Is Nothing Then
            If rtbText.SelectionFont.Bold = True Then
                cmdBold.FlatStyle = FlatStyle.Flat
            Else
                cmdBold.FlatStyle = FlatStyle.System
            End If
            If rtbText.SelectionFont.Italic = True Then
                cmdItalics.FlatStyle = FlatStyle.Flat
            Else
                cmdItalics.FlatStyle = FlatStyle.System
            End If
            If rtbText.SelectionFont.Underline = True Then
                cmdUnderline.FlatStyle = FlatStyle.Flat
            Else
                cmdUnderline.FlatStyle = FlatStyle.System
            End If
        End If
    End Sub


    Private Sub cdmLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cdmLeft.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False

        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop

            rtbText.SelectionAlignment = HorizontalAlignment.Left

            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght
    End Sub

    Private Sub cmdCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCenter.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False

        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop

            rtbText.SelectionAlignment = HorizontalAlignment.Center

            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght
    End Sub

    Private Sub cmdRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRight.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False

        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop

            rtbText.SelectionAlignment = HorizontalAlignment.Right

            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles panColors.Paint

    End Sub

    Private Sub cmdColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColor.Click
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = True
    End Sub

    Private Sub PicClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox19.Click, PictureBox18.Click, PictureBox17.Click, PictureBox16.Click, PictureBox24.Click, PictureBox23.Click, PictureBox22.Click, PictureBox21.Click, PictureBox34.Click, PictureBox33.Click, PictureBox32.Click, PictureBox31.Click, PictureBox29.Click, PictureBox28.Click, PictureBox27.Click, PictureBox26.Click, PictureBox40.Click, PictureBox39.Click, PictureBox38.Click, PictureBox37.Click, PictureBox36.Click, PictureBox6.Click, PictureBox5.Click, PictureBox4.Click, PictureBox9.Click, PictureBox8.Click, PictureBox7.Click, PictureBox12.Click, PictureBox11.Click, PictureBox10.Click, PictureBox15.Click, PictureBox14.Click, PictureBox13.Click
        Dim start As Integer = rtbText.SelectionStart
        Dim lenght As Integer = rtbText.SelectionLength

        Dim curStart As Integer = start

        Do
            rtbText.SelectionStart = curStart
            rtbText.SelectionLength = (start + lenght) - curStart

            Do While rtbText.SelectionFont Is Nothing
                rtbText.SelectionLength -= 1
            Loop
            rtbText.SelectionColor = sender.backcolor
            curStart = rtbText.SelectionStart + rtbText.SelectionLength
        Loop While curStart < (start + lenght)
        rtbText.SelectionStart = start
        rtbText.SelectionLength = lenght

        panColors.Visible = False
    End Sub

    Private Sub cmdFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFont.Click
        If Not rtbText.SelectionFont Is Nothing Then
            lstFonts.SelectedItem = rtbText.SelectionFont.FontFamily.ToString
        Else
            lstFonts.SelectedItem = Nothing
        End If
        panSize.Visible = False
        panColors.Visible = False
        panFont.Visible = True
    End Sub

    Private Sub lstFonts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFonts.SelectedIndexChanged
        If Not lstFonts.SelectedItem Is Nothing Then
            Dim start As Integer = rtbText.SelectionStart
            Dim lenght As Integer = rtbText.SelectionLength

            Dim curStart As Integer = start

            Do
                rtbText.SelectionStart = curStart
                rtbText.SelectionLength = (start + lenght) - curStart

                Do While rtbText.SelectionFont Is Nothing
                    rtbText.SelectionLength -= 1
                Loop
                rtbText.SelectionFont = New Font(CStr(lstFonts.SelectedItem), rtbText.SelectionFont.Size)
                curStart = rtbText.SelectionStart + rtbText.SelectionLength
            Loop While curStart < (start + lenght)
            rtbText.SelectionStart = start
            rtbText.SelectionLength = lenght

            panFont.Visible = False
        End If
    End Sub

    Private Sub cmdSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSize.Click
        If Not rtbText.SelectionFont Is Nothing Then
            lstSize.SelectedItem = CStr(rtbText.SelectionFont.SizeInPoints)
        Else
            lstFonts.SelectedItem = Nothing
        End If
        panFont.Visible = False
        panColors.Visible = False
        panSize.Visible = True
    End Sub

    Private Sub lstSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSize.SelectedIndexChanged
        If Not lstSize.SelectedItem Is Nothing Then
            Dim start As Integer = rtbText.SelectionStart
            Dim lenght As Integer = rtbText.SelectionLength

            Dim curStart As Integer = start

            Do
                rtbText.SelectionStart = curStart
                rtbText.SelectionLength = (start + lenght) - curStart

                Do While rtbText.SelectionFont Is Nothing
                    rtbText.SelectionLength -= 1
                Loop
                rtbText.SelectionFont = New Font(rtbText.SelectionFont.FontFamily, CSng(lstSize.SelectedItem))
                curStart = rtbText.SelectionStart + rtbText.SelectionLength
            Loop While curStart < (start + lenght)
            rtbText.SelectionStart = start
            rtbText.SelectionLength = lenght

            panSize.Visible = False
        End If
    End Sub

    Private Sub rtbText_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles rtbText.MouseDown
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False
    End Sub

    Private Sub cmdOther_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOther.Click
        Dim colorPick As New ColorDialog
        With colorPick
            .AllowFullOpen = True
            .FullOpen = True
            .AnyColor = True
            If .ShowDialog = DialogResult.OK Then
                Dim start As Integer = rtbText.SelectionStart
                Dim lenght As Integer = rtbText.SelectionLength

                Dim curStart As Integer = start

                Do
                    rtbText.SelectionStart = curStart
                    rtbText.SelectionLength = (start + lenght) - curStart

                    Do While rtbText.SelectionFont Is Nothing
                        rtbText.SelectionLength -= 1
                    Loop
                    rtbText.SelectionColor = .Color
                    curStart = rtbText.SelectionStart + rtbText.SelectionLength
                Loop While curStart < (start + lenght)
                rtbText.SelectionStart = start
                rtbText.SelectionLength = lenght

                panColors.Visible = False
            End If
        End With
    End Sub

    Public Property RTFtext() As String
        Get
            Return rtbText.Rtf
        End Get
        Set(ByVal Value As String)
            rtbText.Rtf = Value
        End Set
    End Property

    Public Function HTMLtext() As String
        Dim rtb As New RichTextBox
        rtb.Rtf = rtbText.Rtf

        Dim tagsIn As New ArrayList

        Dim HTML As New StringBuilder

        For i As Integer = 0 To rtb.TextLength
            rtb.SelectionStart = i
            rtb.SelectionLength = 1
            Dim chr As String = rtb.SelectedText
            Dim chrbold As Boolean = rtb.SelectionFont.Bold
            Dim chritalic As Boolean = rtb.SelectionFont.Italic
            Dim chrunderline As Boolean = rtb.SelectionFont.Underline
            Dim chrfont As String = rtb.SelectionFont.Name
            Dim chrsize As String = rtb.SelectionFont.SizeInPoints
            Dim chrcolor As Color = rtb.SelectionColor
            Dim chralign As String
            Select Case rtb.SelectionAlignment
                Case HorizontalAlignment.Left
                    chralign = "Left"
                Case HorizontalAlignment.Center
                    chralign = "Center"
                Case HorizontalAlignment.Right
                    chralign = "Right"
            End Select

            Dim needsOff As New ArrayList
            Dim needsOn As New ArrayList

            If tagsIn.Contains("<b>") = True And chrbold = False Then
                needsOff.Add("<b>")
            ElseIf tagsIn.Contains("<b>") = False And chrbold = True Then
                needsOn.Add("<b>")
            End If

            If tagsIn.Contains("<i>") = True And chritalic = False Then
                needsOff.Add("<i>")
            ElseIf tagsIn.Contains("<i>") = False And chritalic = True Then
                needsOn.Add("<i>")
            End If

            If tagsIn.Contains("<u>") = True And chrunderline = False Then
                needsOff.Add("<u>")
            ElseIf tagsIn.Contains("<u>") = False And chrunderline = True Then
                needsOn.Add("<u>")
            End If

            If tagsIn.Contains("<font face=""" & chrfont & """>") = False Then
                needsOn.Add("<font face=""" & chrfont & """>")
                For Each tagOn As String In tagsIn
                    If tagOn.StartsWith("<font face=") = True Then
                        needsOff.Add(tagOn)
                        Exit For
                    End If
                Next
            End If

            If tagsIn.Contains("<font style=""font-size:" & chrsize & ";"">") = False Then
                needsOn.Add("<font style=""font-size:" & chrsize & ";"">")
                For Each tagOn As String In tagsIn
                    If tagOn.StartsWith("<font style=""font-size:") = True Then
                        needsOff.Add(tagOn)
                        Exit For
                    End If
                Next
            End If

            If tagsIn.Contains("<font color=""" & System.Drawing.ColorTranslator.ToHtml(chrcolor) & """>") = False Then
                needsOn.Add("<font color=""" & System.Drawing.ColorTranslator.ToHtml(chrcolor) & """>")
                For Each tagOn As String In tagsIn
                    If tagOn.StartsWith("<font color=") = True Then
                        needsOff.Add(tagOn)
                        Exit For
                    End If
                Next
            End If

            If tagsIn.Contains("<p align=""" & chralign & """>") = False Then
                needsOn.Add("<p align=""" & chralign & """>")
                For Each tagOn As String In tagsIn
                    If tagOn.StartsWith("<p align=") = True Then
                        needsOff.Add(tagOn)
                        Exit For
                    End If
                Next
            End If

            Dim startTags As New ArrayList

            Dim stillOn As New ArrayList

            For j As Integer = (tagsIn.Count - 1) To 0 Step -1
                Dim tagOn As String = tagsIn(j)
                If needsOff.Contains(tagon) = True Then
                    For Each stillOntag As String In stillOn
                        startTags.Add(stillOntag)
                        HTML.Append(EndTag(stillOntag))
                        tagsIn.Remove(stillOntag)
                    Next
                    stillOn.Clear()
                    HTML.Append(EndTag(tagon))
                    tagsIn.Remove(tagon)
                Else
                    stillOn.Add(tagon)
                End If
            Next
            For Each startTag As String In startTags
                HTML.Append(startTag)
                tagsIn.Add(startTag)
            Next
            For Each startTag As String In needsOn
                HTML.Append(startTag)
                tagsIn.Add(startTag)
            Next
            If chr Is vbNewLine Then
                HTML.Append("<br>")
            Else
                HTML.Append(chr)
            End If



        Next

        For i As Integer = (tagsIn.Count - 1) To 0 Step -1
            Dim tagOn As String = tagsIn(i)
            HTML.Append(EndTag(tagon))
        Next

        Return HTML.ToString
    End Function

    Private Function EndTag(ByVal startTag As String) As String
        If startTag = "<b>" Then
            Return "</b>"
        ElseIf startTag = "<u>" Then
            Return "</u>"
        ElseIf startTag = "<i>" Then
            Return "</i>"
        ElseIf startTag.StartsWith("<font") = True Then
            Return "</font>"
        Else
            Return "</p>"
        End If
    End Function

    Private Sub lstSize_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSize.Resize
        panSize.Height = lstSize.Height + 2
    End Sub

    Private Sub lstFonts_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFonts.Resize
        panFont.Height = lstFonts.Height + 2
    End Sub

    Private Sub RichTextEditor_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus
        panSize.Visible = False
        panFont.Visible = False
        panColors.Visible = False
    End Sub
End Class
