gpt4 book ai didi

c# - 使用自定义图像按钮在 RichTextBox 中显示图像

转载 作者:行者123 更新时间:2023-11-30 18:37:24 25 4
gpt4 key购买 nike

我正在创建一个类似于记事本/word 的文本编辑器,我的表单上有按钮,并附有自定义图像。图像已加载到资源文件夹中。现在,当我单击按钮时,我希望它在 RichTextBox 中显示相同的图像,显​​示的图像将是各种表情符号。我只找到了创建图片查看器的方法,而不是这个。

private void button11_Click(object sender, EventArgs e)    
{
Image.FromFile("../../Resources/sad-icon.png");
}

这将用于在 RichTextBox 中放置一个悲伤的表情符号。这是我到目前为止所拥有的,我对 C# 还很陌生。

最佳答案

我一直在尝试各种方法,我找到了一种方法,但只适用于某些表情符号,而不是我需要能够使用的表情符号。

        void InsertEmoticon(string ImageName)
{
int StringLength = 0;
StringLength = txtPAD.Text.Length;
Image img = Image.FromFile("../../Resources/Emoticons/" + ImageName + ".png");
Clipboard.SetImage(img);
txtPAD.SelectionStart = (StringLength + 1);
txtPAD.Paste();
txtPAD.Clear();
}

然后我将使用:

 private void button10_Click(object sender, EventArgs e)
{
InsertEmoticon("glad");
}

我在这里遗漏了什么吗?图像已加载到资源文件夹中,位于 Emoticons 文件夹中。

关于c# - 使用自定义图像按钮在 RichTextBox 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12863098/

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