【问题标题】:Using custom image buttons to display an image in RichTextBox使用自定义图像按钮在 RichTextBox 中显示图像
【发布时间】:2012-10-12 16:10:41
【问题描述】:

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

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

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

【问题讨论】:

  • 您是在 WinForms 还是 WPF 中工作?

标签: c# winforms image imagebutton


【解决方案1】:

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

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

我在这里错过了什么吗?图片已加载到资源文件夹中,位于表情文件夹中。

【讨论】:

    猜你喜欢
    • 2021-12-16
    • 2014-05-07
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2018-08-05
    相关资源
    最近更新 更多