Results 1 to 3 of 3

Thread: [RichTextBox] [Helper] - Emoticonizer Helper Class

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    [RichTextBox] [Helper] - Emoticonizer Helper Class

    In the attachment is a class that can generate emoticons in a RichTextBox control, called "Emoticonizer".

    Four key components are used:
    Code:
    Public Shared Sub Init(Optional ByVal smileyfolder As String = "smileys")
    Initializes the smiley images and adds them into a HashTable. You can specify a custom folder path where the smiley images are, but that is optional.
    To customize the smileys, change the Init subroutine to contain your new smiley(s):
    Code:
    emoticontable.Add(";)", New Bitmap(smileyfolder & "\smiley1.gif"))
    Code:
    Public Shared Sub Dispose()
    Disposes all smiley images and clears the Emoticon Table.
    This should be called when your program closes or when you no longer need emoticon support.
    If you want to re-initialize, you have to call Dispose first.

    Code:
    Public Shared Sub Emoticonize(ByVal RTB As RichTextBox, Optional ByVal startindex As Integer = 0)
    The main emoticonization code. You specify a RichTextBox control and optionally a character index to start at.
    This subroutine will then store the current (selection)states and locks the control.
    The text fragments that equal a smiley identifier (';)') are selected and replaced by the corresponding smiley image.
    Finally it restores and unlocks the control and makes the control redraw itself.

    Code:
    Public Shared Sub AddMessage(ByVal RTB As RichTextBox, ByVal message As String)
    Appends the message as a new line to the RichTextBox and calls Emoticonize with as starting index the start of the new message.

    You can optionally add a "Buffer RichTextBox control" in the class to obtain the RTF of plain text. Example:
    Code:
        Public Shared Function GetRTF(ByVal text As String) As String
            Dim tmpRTB As New RichTextBox
            tmpRTB.Text = text
            Emoticonize(tmpRTB)
            GetRTF = tmpRTB.Rtf
            tmpRTB.Dispose()
            tmpRTB = Nothing
        End Function
    Finally here a site with smiley images you can test against:
    http://chaaarge.rattleserver.de/smilies.html
    Not sure if it is copyrighted. If it is, message me and I'll remove the link from this post.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width