Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add emoticons to richtextbox

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace abc
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    EmoticonRender ab = new EmoticonRender();
    private void button1_Click(object sender, EventArgs e)
    {
        string textie = ab.Parse(textBox1.Text);
        richTextBox1.Text += textie+"\n";
    }
}
public class EmoticonRender
{

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

    public string Parse(string text)
    {
    foreach(KeyValuePair<string, string> kvp in _dictionary)
    {
    text = text.Replace(kvp.Key, @"C:\Users\Buddiez\Documents\Visual Studio 2010\Projects\abc\abc\a.png");
    }
    return text;
    }

}

}

im using these line of codes to insert smilyes into richtextbox but instead of showing smileye it is showing the path of the png imgae ie. C:\Users\Buddiez\Documents\Visual Studio 2010\Projects\abc\abc\a.png

like image 844
rummykhan Avatar asked Apr 30 '13 20:04

rummykhan


People also ask

How do you put Emojis into input?

To insert a 🙂 emoji, either: Type a colon followed by a keyword, e.g., :smile , then press Enter or Return to add the highlighted emoji, or click the desired emoji from those displayed, or. Select the emoticons toolbar button to open the picker, and use the tabs or search bar to browse, then click the desired emoji.

What is RichTextBox C#?

In C#, RichTextBox control is a textbox which gives you rich text editing controls and advanced formatting features also includes a loading rich text format (RTF) files. Or in other words, RichTextBox controls allows you to display or edit flow content, including paragraphs, images, tables, etc.


2 Answers

Copy all the images which you have and navigate to >> visual studio select Project>>Properties.There select Resources and paste all copied images on the right side pane.

    Hashtable emotions;
    void CreateEmotions()
    {
        emotions= new Hashtable(6);
        emotions.Add(":-)", Project.Properties.Resources.regular_smile);
        emotions.Add(":)",  Project.Properties.Resources.regular_smile);

    }

    void AddEmotions()
    {
        foreach (string emote in emotions.Keys)
        {
            while(richTextBox1.Text.Contains(emote))
            {
                int ind = richTextBox1.Text.IndexOf(emote);
                richTextBox1.Select(ind, emote.Length);
                Clipboard.SetImage((Image)emotions[emote]);
                richTextBox1.Paste();
            }
        }
    }
like image 114
Dot_NET Pro Avatar answered Nov 10 '22 02:11

Dot_NET Pro


A good (and relatively new) solution could be using the open-source EmojiBox project.

There's not much code there so it's quite easy to follow, just note that in order to insert an emoji into the custom RichTextBox there, the text you type has to follow the template of :emoji_name:

Of course, if you don't want to use the whole list of unicode emojis, you could also replace the image files or their names/descriptions within the json file.

like image 1
Yoav Feuerstein Avatar answered Nov 10 '22 04:11

Yoav Feuerstein