截屏函数:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Windows.Forms; 5 //lxw0109 6 using System.Drawing; 7 8 9 namespace WindowsFormsApplication1 10 { 11 static class Program 12 { 13 [STAThread] 14 static void Main() 15 { 16 //下面三行不用管 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 21 //调用截屏函数 22 func(); 23 } 24 public static void func() //截屏函数 25 { 26 int width = Screen.PrimaryScreen.Bounds.Width; 27 int height = Screen.PrimaryScreen.Bounds.Height; 28 Bitmap btm = new Bitmap(width, height); 29 using (Graphics g = Graphics.FromImage(btm)) 30 { 31 g.CopyFromScreen(0, 0, 0, 0, Screen.AllScreens[0].Bounds.Size); 32 g.Dispose(); 33 string save = "F:\" + DateTime.Now.ToString("yyyymmddhhmmssmmmm") + ".jpg"; 34 btm.Save(save); 35 } 36 } 37 } 38 }