开发者

Useful Form Printing

开发者 https://www.devze.com 2023-02-14 08:24 出处:网络
im searching the best way for Printing a whole form / Several Datagridview开发者_开发技巧s and some Specific controll contents in my WindowsForm application.

im searching the best way for Printing a whole form / Several Datagridview开发者_开发技巧s and some Specific controll contents in my WindowsForm application.

I know the internet is full with bad and good examples.

Its hard to separate the Good examples from the Bad examples.

So what can you reccomend me?

Whats your way to do this? Wich Examples in the Web are useful?

Thanks in advance


Try this code. This will print all the contents of the current form.

using (Bitmap bmp = new Bitmap(this.Width, this.Height))
{
    this.DrawToBitmap(bmp, this.ClientRectangle);
    using (PrintDocument p = new PrintDocument())
    {
        p.PrintPage += (o, pe) =>
            {
                pe.Graphics.DrawImage(bmp, this.ClientRectangle);
            };
        p.Print();
    }
}

Sorry I didn't tested it.


you could create a snapshot from the form you want to print and then print the image.

For creating snapshots you could have a look here

0

精彩评论

暂无评论...
验证码 换一张
取 消