richTextBox中的图像 [英] Image in richTextBox

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

问题描述

private void btnPic1_Click(object sender, EventArgs e)
{
    Bitmap bitmap = ActiveWord.Properties.Resources.ah;
    Clipboard.SetImage(bitmap);
    richTextBox.Paste();
}



这段代码来自我正在为大学工作的一个项目.每当我执行这段代码时,图像都不会粘贴到richTextBox中.



This code is taken from a project I am working on for college. Whenever I execute this piece of code, the image is not pasted into the richTextBox.

Any idea how I might be able to fix this?

推荐答案

基本上,它应该可以工作.您需要在调试器下运行它.首先,您需要确保bitmap确实包含图像,然后确保剪贴板包含图像& mdasj;.只需打开其他可以跳过图形的应用程序,然后在Clipboard.SetImage(bitmap)行之后的断点处停止执行,即可执行过去"命令.第二件事,您需要在Rich框中设置图像的插入点.为此,您需要使用属性SelectionStartSelectionLength.

就这样.

另外,如果您要使用图形,我也不建议使用RichBox控件.有一些不同的方法,比RTF更好.如果您需要建议,则需要标记您喜欢的应用程序类型或UI库(这是什么?表单?WPF?)并解释您的最终用途.

—SA
Basically, it should work. You need to run it under the Debugger. First, you need to makes sure bitmap really contains an image, and then that a clipboard contains the image &mdasj; simply open some other application which can past graphics and perform "Past" command while your execution is stopped at the breakpoint after the line with Clipboard.SetImage(bitmap). Second thing, you need to set insertion point for the image in the rich box. To do so, you need to use the properties SelectionStart and SelectionLength.

That''s it.

Also, I would not advice to use RichBox control if you want to work with graphics. There are some different approached, much better then RTF. If you need an advice on it, you would need to tag the application type or UI library of your preference (what is that? Forms? WPF?) and explain your ultimate purposes.

—SA


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

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