1

I have a RichTextbox in a C# Windows Forms application. I wanna convert the texts like :D or :P to the relevant smileys when some texts arrive to this form.

I have this part of code but whenever the form is updated it removes all smileys that were arrived before and just shows the smileys in the last line.

Is it possible to just update the last line of the form?

foreach (string emot in Emoticons.Keys)
{
    while (RTxtBx_Main.Text.Contains(emot))
    {
        int index = RTxtBx_Main.Text.IndexOf(emot);
        RTxtBx_Main.Select(index, emot.Length);
        Clipboard.SetImage((Image)Emoticons[emot]);
        RTxtBx_Main.Paste();
    }
}
InitLipton
  • 2,395
  • 5
  • 30
  • 47
Payam Sh
  • 581
  • 4
  • 9
  • 21
  • possible duplicate of [How can I insert an image into a RichTextBox?](http://stackoverflow.com/questions/542850/how-can-i-insert-an-image-into-a-richtextbox) – J... Jun 25 '14 at 10:18
  • also : http://stackoverflow.com/q/18017044/327083 , http://stackoverflow.com/q/19067168/327083 – J... Jun 25 '14 at 10:19
  • My code works. But when RTxtBx_Main.Paste() functions, the whole RTxtBx is updated and the last smileys are gone! How to stop this issue? – Payam Sh Jun 25 '14 at 10:30
  • 1
    Your code works fine - I have replaced your Emoticons array with an ImageList. What do you mean by _whenever the form is updated_ **?** I can do a replace, add more text and have the image numbers replace by imgaes again. Nothing is lost. – TaW Jun 25 '14 at 10:53
  • And of course you can use `int lastLine = richTextBox1.Lines.Length - 1;` to get the last line and work on it only. – TaW Jun 25 '14 at 10:58
  • Do you know what the problem was?! The problem was somewhere else! I was using `RTxtBox.Text = RtxtBox.Text + NewData;` So every time the form was updated all of the smileys were gone!!! I replaced it with `RTxtBox.AppendText(NewData)` and yes the problem solved :D tnx for your help anyway :) – Payam Sh Jun 25 '14 at 11:45

0 Answers0