C# Windows form Control to Image?

后端 未结 7 1279
遇见更好的自我
遇见更好的自我 2020-12-18 08:29

I am trying to create an image of a Panel and save it to a folder. The problem is the panel has scrollbars and the image generated is only for the visible portion of the Pan

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 09:25

    No happy answers here, DrawToBitmap can only draw what would be visible to the user. Tricks like changing the Location and Size of the panel beforehand usually quickly run out of gas due to the restriction on the control size imposed by the parent. The form itself can never get larger than the screen, now you'll also depend on the resolution of the video adapter on the target machine.

    One ugly hack is to run DrawToBitmap multiple times, changing the Panel's AutoScrollPosition property between each call. You'd have to stitch the resulting images together. Paying special attention to the last one of course since it won't be as large as the other ones.

    Once you start considering code like this, you really ought to think about PrintDocument or a report generator instead. One benefit to that is that the printout will look a heckofalot cleaner. Printed screen-shots are invariably ugly due to the huge difference in video and printer resolution.

提交回复
热议问题