In the attachment is a class that can generate emoticons in a RichTextBox control, called "Emoticonizer".
Four key components are used:
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.Code:Public Shared Sub Init(Optional ByVal smileyfolder As String = "smileys")
To customize the smileys, change the Init subroutine to contain your new smiley(s):
Code:emoticontable.Add(";)", New Bitmap(smileyfolder & "\smiley1.gif"))Disposes all smiley images and clears the Emoticon Table.Code:Public Shared Sub Dispose()
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.
The main emoticonization code. You specify a RichTextBox control and optionally a character index to start at.Code:Public Shared Sub Emoticonize(ByVal RTB As RichTextBox, Optional ByVal startindex As Integer = 0)
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.
Appends the message as a new line to the RichTextBox and calls Emoticonize with as starting index the start of the new message.Code:Public Shared Sub AddMessage(ByVal RTB As RichTextBox, ByVal message As String)
You can optionally add a "Buffer RichTextBox control" in the class to obtain the RTF of plain text. Example:
Finally here a site with smiley images you can test against: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
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.




Reply With Quote
