Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
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 27-Sep-12 21:47pm

Comments
Kenneth Haugland - 28-Sep-12 4:00am
Pictures?
gladiatron - 28-Sep-12 4:13am
or GIF animations??

4 solutions

You need to write some type of text parser!
 
Here is a brief example:
 
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:
 
string text = "hello :-) don't be sad ;-(";
EmoticonRender parser = new EmoticonRender();
string parsedText = parser.Parse(text); 
  Permalink  
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/".....
  Permalink  
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
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 477
1 Ron Beyer 316
2 samadhan_kshirsagar 269
3 Tadit Dash 243
4 OriginalGriff 181
0 Sergey Alexandrovich Kryukov 7,061
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,370
4 CPallini 3,034


Advertise | Privacy | Mobile
Web04 | 2.6.130619.1 | Last Updated 7 Jun 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid