richTextBox.DrawToBitmap Does Not Draw Containing Text?

后端 未结 6 1414
盖世英雄少女心
盖世英雄少女心 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:01

    I know this is relatively old, but a working solution that I found at http://www.windows-tech.info/3/8ffaf21eed5de2d4.php:

    public static Bitmap RtbToBitmap(RichTextBox rtb)
    {
        rtb.Update(); // Ensure RTB fully painted
        Bitmap bmp = new Bitmap(rtb.Width, rtb.Height);
        using (Graphics gr = Graphics.FromImage(bmp))
        {
            gr.CopyFromScreen(rtb.PointToScreen(Point.Empty), Point.Empty, rtb.Size);
        }
        return bmp;
    }
    

提交回复
热议问题