本文介绍了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?

推荐答案

此线程在Google中排名第二.似乎正是您想要的.因为我想您正在此问题中的函数内部使用此函数接受表单元素作为方法参数?,最好是做这样的事情.

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

10-28 16:55