作者: Miklogak
查看: 487|回复: 1
打印 上一主题 下一主题

[源码] 【RTF文本框】在 RichTextBox 中自动加载笑脸

[复制链接]
跳转到指定楼层
楼主
查看: 487|回复: 1
说明:
在 RichTextBox 中自动加载笑脸
在您键入时自动在 RichTextBox 中加载笑脸的简单 WinForm 应用程序我还在下面附上了 .zip 源代码

效果截图:


部分代码:
[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();
        }
    }
}


案例源码:


评分

参与人数 1金钱 +5 收起 理由
乔克斯 + 5 感谢LZ对论坛做出的贡献~

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播
回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-5-6 22:43, Processed in 0.569384 second(s), 34 queries , Gzip On.

快速回复 返回顶部 返回列表