Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Can you help me regarding adding emoticons to our asp.net chat application.

please provide me the code for adding smileys to my asp.net website in c#.






Regards
sonam vij
Posted
Comments
Kenneth Haugland 28-Sep-12 4:00am    
Pictures?
I.explore.code 28-Sep-12 4:13am    
or GIF animations??

You need to write some type of text parser!

Here is a brief example:

C#
public class EmoticonRender()
{

  private List<keyvaluepair<string,string>> _dictionary = new List<keyvaluepair<string,string>>() 
  {
    new KeyValuePair<string,>(":-)", "smile.png"),
    new KeyValuePair<string,>(";-(", "cry.png")
  }

  public string Parse(string text)
  {
    foreach(KeyValuePair<string,> kvp in _dictionary)
    {
      text = text.Replace(kvp.Key, "<img src="\""" kvp.value="" />");
    }
    return text;
  }

}


The class looks the the text representation of the emoticons and replaces them with the HTML required to render the images.

Usage is simple:

C#
string text = "hello :-) don't be sad ;-(";
EmoticonRender parser = new EmoticonRender();
string parsedText = parser.Parse(text); 
 
Share this answer
 
v2
If you want selectable text with inserted emoticon images, I think you have 3 relatively simple options:

1. Use a WebBrowser instead of a TextBox and create html from your text+images.
2. Use a RichTextBox instead of a TextBox and insert your images into the RTF.
3. Buy a third party advanced TextBox-ish control which offers the ability to override the drawing event.

Or try : Inserting Plain Text and Images into RichTextBox at Runtime[^].


--Amit
 
Share this answer
 
v2
hello sonam, for your solution you could go-through the link "http://stackoverflow.com/questions/13528276/how-to-add-smiley-feature-in-chat-application-in-java" and for live demo (which using jquery for smiley) use link "http://jsfiddle.net/Etmrs/".....
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900