richTextBox.DrawToBitmap 不绘制包含文本?
如果我有一个 richTextBox 并在其上运行 DrawToBitmap,它不会绘制 richTextBox 内的任何文本。
Bitmap b = new Bitmap(rtb.Width, rtb.Height);
inputControl.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height));
有什么办法可以解决这个问题吗?
If I have a richTextBox and run DrawToBitmap on it, it doesn't draw any of the text inside of the richTextBox.
Bitmap b = new Bitmap(rtb.Width, rtb.Height);
inputControl.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height));
Is there any way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道这是相对较旧的,但我在 http://www. windows-tech.info/3/8ffaf21eed5de2d4.php:
I know this is relatively old, but a working solution that I found at http://www.windows-tech.info/3/8ffaf21eed5de2d4.php:
此帖子 在 Google 中排名第二。似乎正是您想要的。因为我想您在这个问题的函数中使用它 接受表单元素作为方法参数?,最好这样做。
您可以递归地检查包含 RichTextBox 的控件,
我还没有编译它,并且有一种方法可以在不冒 StackOverflowException 风险的情况下执行此操作,但这应该可以帮助您入门。
This thread came up second in Google. Seems to have exactly what you want. Because I imagine you're using this inside your function from this question Accepting Form Elements As Method Arguments?, it's probably best to do something like this.
You can check for a Control containing RichTextBox recursively
I haven't compiled this, and there's a way of doing it without risking a StackOverflowException, but this should get you started.
来自 RichTextBox.DrawToBitmap() 的 MSDN 库文章:
一种糟糕的说法是本机 Windows richedit 控件不支持 WM_PRINT。可以选择截屏,诺维科夫为您提供了我的答案的链接。
From the MSDN Library article for RichTextBox.DrawToBitmap():
A crummy way to say that the native Windows richedit control doesn't support WM_PRINT. Taking a screen shot is an option, Novikov gave you a link to my answer.
值得一提的是,RichTextBox 控件的更高版本可以正确支持 DrawToBitmap 方法;它还提高了性能并具有更多功能。
For what it's worth, the later version of the RichTextBox control supports the DrawToBitmap method properly; it also improves performance and has more features.
我在这里找到了相关的答案:如何以正确的格式在任何设备环境上打印富文本框内容?
我更改了此设置以将屏幕外的 RichTextBox 渲染为位图。这样我就可以在屏幕外创建一个位图,然后将其发送到 OpenGL。
I found a related answer here: how to print Rich text box contents on any device contenxt with proper formatting?
I changed this to render my off screen RichTextBox to a bitmap. This way I could create a bitmap off screen and then send it to OpenGL.
我测试了上面的方法,每当我将保存的位图加载到 ImageViewer(如 Paint)中时,它都会使 SaveFileDialog-UI 淡入文本的背景中。幸运的是,我找到了一个简单的解决方法:
Save
之前绘制图片(别担心,在您按下之前它不会真正保存图像保存
)按
取消
不会影响该过程,因为当您按Button
或MenuStripItem
进行保存时它,它将更新&重新绘制它:)我实现了一个
try
-catch
方法,这样如果发生错误,它就会捕获错误,而不是应用程序只是(Not Responding )
catch
方法是一个Retry
Button
它将捕获错误,并让您选择
Cancel
整个操作
,或重试
我使用了
goto
来倒带,并再次尝试保存文件,而不是让SaveFileDialog
再次出现。我希望这对你有帮助:)
I tested the methods above, and whenever I load the saved Bitmap into an ImageViewer(Like Paint), it would have the SaveFileDialog-UI faded into the background of the text. Luckily, I found an easy fix:
Save
(Don't worry, it won't actually save the image until you pressSave
)Pressing
Cancel
doesn't effect the process, because when you press theButton
orMenuStripItem
to save it, it will update & re-paint it :)I implemented a
try
-catch
method, so that it will catch an error if one occurs, rather than the app just(Not Responding)
The
catch
method is aRetry
Button
It will catch the error, and give you the choice to either
Cancel
the wholeOperation
, orRetry
I used a
goto
to be able to just rewind, and make another attempt to save the file, rather than having theSaveFileDialog
appear again.I hope this helps you :)