Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
Hashtable emotions;
         private void CreateEmotions()
         {
             emotions = new Hashtable(12);
             emotions.Add(@":)", Properties.Resources.ThumbsUp1);
             emotions.Add(@"0)", Properties.Resources.AngelSmile1);
             emotions.Add(@":(", Properties.Resources.CrySmile1);
             emotions.Add(@":X", Properties.Resources.AngrySmile1);
             emotions.Add(@"XX", Properties.Resources.DevilSmile); 
         }
      
         private void AddEmotions(Hashtable emotions)
         {
             foreach (string emote in emotions.Keys)
                 while (txtLoad.Text.Contains(emote))
                 {
                     int ind = txtLoad.Text.IndexOf(emote);
                     txtLoad.Select(ind, emote.Length);
                     Clipboard.SetImage((Image)emotions[emote]);
                     txtLoad.Paste();
                 }
         }



I am using these lines of code to insert smileys into my richtextbox but when I send the message it shows what I type and not the image.

C#
if (msgReceived.strMessage != null && msgReceived.cmdCommand !=Command.List)
               txtLoad.Text += msgReceived.strMessage + "\r\n";    


That code sets the richtextbox text, adds the messages typed by the users.

What I have tried:

Looking for help online, and other examples...
Posted
Updated 16-Oct-20 10:31am
v4

Not sure how much you really searched, because this article was easy enough to find.

Insert Plain Text and Images into RichTextBox at Runtime[^]

I think this is what you are looking for.
 
Share this answer
 
Comments
Itamarc101 10-May-16 18:39pm    
I have tried that it just has some errors...
George Jonsson 10-May-16 19:10pm    
Well, you should have mentioned that article in the "What I have tried" section.

And what is "some errors"? Something you can fix perhaps?
Itamarc101 10-May-16 19:17pm    
Now I changed the code, I'm using that one.
Hashtable emotions;
private void CreateEmotions()
{
emotions = new Hashtable(5);
emotions.Add(":)", Properties.Resources.ThumbsUp1);
emotions.Add("0)", Properties.Resources.AngelSmile1);
emotions.Add(":(", Properties.Resources.CrySmile1);
emotions.Add(":X", Properties.Resources.AngrySmile1);
emotions.Add("XX", Properties.Resources.DevilSmile);

}

private void AddEmotions(Hashtable emotions)
{
foreach (string emote in emotions.Keys)
while (txtLoad.Text.Contains(emote))
{
int ind = txtLoad.Text.IndexOf(emote);
txtLoad.Select(ind, emote.Length);
Clipboard.SetImage((Image)emotions[emote]);
txtLoad.Paste();
}
}

I added all the images to Resource (In Properties)
https://i.gyazo.com/8d127e848698c9b0786825f5b179f0af.png

And it doesnt work, just shows the same letters I type.
https://i.gyazo.com/e3f7be8a37675d9e22391a08940ecbf8.png

That's the command that prints the normal msg on the richtextbox:

if (msgReceived.strMessage != null && msgReceived.cmdCommand != Command.List)
{
txtLoad.Text += msgReceived.strMessage + "\r\n";

}
txtLoad is the textbox.
What is wrong?
George Jonsson 10-May-16 22:49pm    
You kind of have the wrong approach.
Study the article, download the code and try it out.
It has a working demo, that you can learn from.
Itamarc101 11-May-16 1:16am    
Ill try my best to do that today.
Just change TextBox to RichTextBox this will work
 
Share this answer
 
Comments
CHill60 19-Oct-20 4:45am    
OP is already trying to use a RichTextBox - read the question carefully.

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