Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use this Emoticons function below:</p> <pre><code> #region add emotion to RichTextBox function private Dictionary&lt;string, string&gt; _mappings = new Dictionary&lt;string, string&gt;(); private string GetEmoticonText(string text) { string match = string.Empty; int lowestPosition = text.Length; foreach (KeyValuePair&lt;string, string&gt; pair in _mappings) { if (text.Contains(pair.Key)) { int newPosition = text.IndexOf(pair.Key); if (newPosition &lt; lowestPosition) { match = pair.Key; lowestPosition = newPosition; } } } return match; } // And also function which add smiles in richtextbox, here is it: private void Emoticons(string msg,Paragraph para ) { //try //{ // Paragraph para = new Paragraph { LineHeight = 1 }; Run r = new Run(msg); para.Inlines.Add(r); string emoticonText = GetEmoticonText(r.Text); //if paragraph does not contains smile only add plain text to richtextbox rtb2 if (string.IsNullOrEmpty(emoticonText)) { rtbConversation.Document.Blocks.Add(para); } else { while (!string.IsNullOrEmpty(emoticonText)) { TextPointer tp = r.ContentStart; // keep moving the cursor until we find the emoticon text while (!tp.GetTextInRun(LogicalDirection.Forward).StartsWith(emoticonText)) tp = tp.GetNextInsertionPosition(LogicalDirection.Forward); // select all of the emoticon text var tr = new TextRange(tp, tp.GetPositionAtOffset(emoticonText.Length)) { Text = string.Empty }; //relative path to image smile file string path = _mappings[emoticonText]; Image image = new Image { Source = new BitmapImage(new System.Uri(Environment.CurrentDirectory+path, UriKind.RelativeOrAbsolute)), Width = Height = 25, }; //insert smile new InlineUIContainer(image, tp); if (para != null) { var endRun = para.Inlines.LastInline as Run; if (endRun == null) { break; } else { emoticonText = GetEmoticonText(endRun.Text); } } } rtbConversation.Document.Blocks.Add(para); } } // /// private void Window_Loaded(object sender, RoutedEventArgs e) { _mappings.Add(@"s-]", "/Images/smiley/silly.png"); _mappings.Add(@":-|", "/Images/smiley/angry.png"); } //Call function to use private void SendMessage(object sender,RoutedEventArgs e) { Paragraph paragraph = new Paragraph(); paragraph.LineHeight = 1; Run name = new Run(); name.Text =rtbMessage.Text+ " : "; name.Foreground = new SolidColorBrush(Colors.Red); paragraph.Inlines.Add(new Bold(name)); //paragraph.Inlines.Add(new Run(name.text)); rtbConversation.Document.Blocks.Add(paragraph); Emoticons(name.Text, paragraph); rtbConversation.ScrollToEnd(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload