Archive for the ‘Image’ Category

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


How to convert .net Form to Image
  1. Public Class Form1
  2.  
  3.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  4.         CreateBitmap(Me)
  5.     End Sub
  6.  
  7.     Private Sub CreateBitmap(ByVal con As Control)
  8.         'Dim g As Graphics = Me.CreateGraphics()
  9.  
  10.         Dim b As Bitmap = New Bitmap(Me.Width, Me.Height)
  11.         Me.DrawToBitmap(b, New Rectangle(0, 0, Me.Width, Me.Height))
  12.  
  13.         b.Save("test.jpg", Imaging.ImageFormat.Jpeg)
  14.         b.Dispose()
  15.         'g.Dispose()
  16.     End Sub
  17. End Class

, ,

No Comments



SetPageWidth