如何用图像替换文本 [英] How to replace a text with an image

查看:77
本文介绍了如何用图像替换文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void txtLog_TextChanged(object sender, EventArgs e)
        {
            Image img = Image.FromFile("C:/Dokumente und Einstellungen/mgmeiner/Desktop/smile3.gif");
            string smile1 = ":)";
            if (txtLog.Text.Contains(smile1))
            {
                txtLog.Text = txtLog.Text.Replace(":)", Clipboard.SetImage(img));
            }
        }



但这不起作用!



But this doesn''t work!

推荐答案

那是因为它是一个文本框,而不是图像的默认占位符.您将不得不自己绘制控件,当遇到序列":)"时,您不会绘制字母,而是绘制图像.除了简单地用图像替换文本序列以外,还有很多工作要做.现在,您要混合使用不同的类型.

但是,您可以使用已经具有实现功能的rtf控件,请在此处查看:

http://www.codeproject.com/KB/edit/csexrichtextbox.asp [ ^ ]

祝你好运!
That''s because it''s a textbox and not a default placeholder for images. You would have to draw the control yourself and when you encounter the sequence ":)" you wouldn''t draw the letters but the image instead. There is some more work to it than simply replacing a text sequence by an image. You are now mixing different types that do not apply.

You could however use an rtf control that already has implementation for this, have a look here:

http://www.codeproject.com/KB/edit/csexrichtextbox.asp[^]

Good luck!




尝试使用Rich Textbox控件...

网络中有一些帖子...请参阅此... http://www.daniweb.com/forums/thread25861 .html [^ ]

问候,
Suresh
Hi,

Try using Rich Textbox control...

There are some posts in the net... See this... http://www.daniweb.com/forums/thread25861.html[^]

Regards,
Suresh


这篇关于如何用图像替换文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆