gpt4 book ai didi

c#-4.0 - 如何将表情符号添加到富文本框

转载 作者:行者123 更新时间:2023-12-04 15:45:34 24 4
gpt4 key购买 nike

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;
}

}

}

我使用这些代码行将笑脸插入到 Richtextbox 中,但不是显示笑脸,而是显示 png imgae 的路径,即。 C:\Users\Buddiez\Documents\Visual Studio 2010\Projects\abc\abc\a.png

最佳答案

复制您拥有的所有图像并导航到 >> Visual Studio 选择 Project>>Properties.There 选择 Resources 并将所有复制的图像粘贴到右侧 Pane 中。

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

关于c#-4.0 - 如何将表情符号添加到富文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16308210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com