WinForm版 屏幕截圖

環境:ide

Vs 2015spa

.net 4.5.2.net

 

源碼:線程

        public static void toScreen()
        {
            ThreadStart ts = new ThreadStart(() =>//開線程
              {
                  Screen scr = Screen.PrimaryScreen;
                  Rectangle rc = scr.Bounds;
                  int iWidth = rc.Width;
                  int iHeight = rc.Height;
                  Image myImage = new Bitmap(iWidth, iHeight);
                  Graphics gs = Graphics.FromImage(myImage);
                  gs.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
                  string sFilesName = DateTime.Now.ToString("yyyyMMddHHmmss");//文件名
                  string sPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);//獲取桌面路徑
                  myImage.Save($@"{sPath}\{sFilesName}.bmp");
              });
            Thread thread = new Thread(ts);
            thread.Start();
        }
View Code
相關文章
相關標籤/搜索