Posts Tagged ‘drawing’

How to Capture form without showing it in .Net

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5.  
  6. public class ControlPainter
  7. {
  8.   private const int
  9.     WM_PRINT = 0×317, PRF_CLIENT = 4,
  10.     PRF_CHILDREN = 0×10, PRF_NON_CLIENT = 2,
  11.     COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;
  12.  
  13.   [DllImport("USER32.DLL")]
  14.   private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);
  15.  
  16.   public static void PaintControl(Graphics graphics, Control control)
  17.   { // paint control onto graphics
  18.     IntPtr hWnd = control.Handle;
  19.     IntPtr hDC = graphics.GetHdc();
  20.     SendMessage(hWnd, WM_PRINT, hDC, COMBINED_PRINTFLAGS);
  21.     graphics.ReleaseHdc(hDC);
  22.   }
  23. }
  24.  
  25. <strong>TO USE IT:
  26. </strong>
  27. using (Form f = new MyForm()) {
  28. Image i = new Image(f.Width, f.Height);
  29. Graphics g = Graphics.FromImage(i);
  30. ControlPainter.PaintControl(g, f);
  31. }

Source

Reference

,

No Comments



SetPageWidth