richTextBox.DrawToBitmap Does Not Draw Containing Text?

后端 未结 6 1372
盖世英雄少女心
盖世英雄少女心 2021-01-15 14:34

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         


        
6条回答
  •  余生分开走
    2021-01-15 15:21

    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
    }
    

    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;
    }
    

    I haven't compiled this, and there's a way of doing it without risking a StackOverflowException, but this should get you started.

提交回复
热议问题