[C#] 纯文本查看 复制代码
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;
using System.Collections;
namespace SmileyDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//笑脸哈希表
Hashtable emotions;
//在下方添加您的笑脸代码
void CreateEmotions()
{
emotions= new Hashtable(6);
emotions.Add(":-)", SmileyDemo.Properties.Resources.regular_smile);
emotions.Add(":)", SmileyDemo.Properties.Resources.regular_smile);
emotions.Add(":-(", SmileyDemo.Properties.Resources.sad_smile);
emotions.Add(":(", SmileyDemo.Properties.Resources.sad_smile);
emotions.Add(":-P", SmileyDemo.Properties.Resources.tongue_smile);
emotions.Add(":P", SmileyDemo.Properties.Resources.tongue_smile);
}
//添加到 RichTextBox
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();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
//加载表情
CreateEmotions();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
//在打字时添加笑脸
AddEmotions();
}
}
}