richTextBox.DrawToBitmap不绘制包含文本吗? [英] richTextBox.DrawToBitmap Does Not Draw Containing Text?

查看:119
本文介绍了richTextBox.DrawToBitmap不绘制包含文本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个richTextBox并在其上运行DrawToBitmap,它不会在richTextBox内绘制任何文本.

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?

推荐答案

接受表单元素作为方法参数?,最好是做这样的事情.

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.

if(inputControl is RichTextBox)
{
    //do specifc magic here
}
else
{
    //general case
}

您可以递归检查包含RichTextBox的控件

You can check for a Control containing RichTextBox recursively

bool ContainsOrIsRichTextBox(Control inputControl)
{
    if(inputControl is RichTextBox) return true;
    foreach(Control control in inputControl.Controls)
    {
        if(ContainsOrIsRichTextBox(control)) return true;
    }
    return false;
}

我还没有编译它,有一种方法可以在不冒StackOverflowException风险的情况下进行操作,但这应该可以帮助您入门.

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不绘制包含文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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