Is there an easy way to print my clean windows form?

I just created a database application to request details.

It has several forms, one for the requester, one for approving the supervisor, one for approving the purchase, and one for the clerk to know what to order.

Now I am a big fan of paperless, but my employer Really likes their paper. Is there an easy way for WYSIWYG to duplicate my windows forms onto paper?

I should also add that I am limited to using the 2.0.Net framework

thanks

+3
source share
2 answers

Here is an example of code from MSDN that will do what you want:

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
   Graphics mygraphics = this.CreateGraphics();
   Size s = this.Size;
   memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
   Graphics memoryGraphics = Graphics.FromImage(memoryImage);
   IntPtr dc1 = mygraphics.GetHdc();
   IntPtr dc2 = memoryGraphics.GetHdc();
   BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
   mygraphics.ReleaseHdc(dc1);
   memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
   e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
   CaptureScreen();
   printDocument1.Print();
}

- , , API BitBlt, , , Windows Forms .

+2

. , :

    public static class FormExtensions
    {
        public static void PrintForm(this Form f)
        {
            PrintDocument doc = new PrintDocument();
            doc.PrintPage += (o, e) =>
            {
                Bitmap image = new Bitmap(f.ClientRectangle.Width, f.ClientRectangle.Height);
                f.DrawToBitmap(image, f.ClientRectangle);

                e.Graphics.DrawImage(image, e.PageBounds);
            };

            doc.Print();
        }
    }

. DrawImage , .

+4

Source: https://habr.com/ru/post/1704599/


All Articles