2013-04-30 10 views
6
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; 
    } 

} 

}ekleme ifadeler RichTextBox smilyes eklemek için kodlar, bu hat kullanılarak

im richtextbox yerine gösteren bu PNG imgae yani yolunu gösteren smileye için. C: \ Users \ Buddiez \ Documents \ Visual Studio 2010 \ Projects \ abc \ abc \ a.png

+0

olası bir kopyası [Bir RichTextBox'a nasıl görüntü ekleyebilirim?] (Http://stackoverflow.com/questions/542850/how-can-i-insert-an-image-into-a-richtextbox) –

+0

Bu anahtarı sevdim :) – nawfal

+0

herhangi bir şans kardeşin? – zzlalani

cevap

1

Bulunduğunuz tüm resimleri kopyalayın ve >> görsel stüdyosu seçin Proje >> Özellikler bölümüne gidin. tüm kopyalanan görüntüleri sağ taraftaki bölme üzerine yapıştırın.

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(); 
      } 
     } 
    } 
+0

bildiririz bu en iyi çözümdür. harika çalışıyor. Teşekkürler. – jonathana

1

iyi (ve nispeten yeni) çözeltisi açık kaynak EmojiBox proje kullanarak olabilir. emoji_name:

oldukça takip etmek kolaydır, böylece sadece orada özel RichTextBox bir ifade eklemek için dikkat Orada çok kod bile yok, yazdığınız metinler şablonunu takip etmelidir Elbette, tüm unicode emojis listesini kullanmak istemezseniz, json dosyasındaki görüntü dosyalarını veya adlarını/açıklamalarını da değiştirebilirsiniz.