2015-02-24 78 views
0

我有一個在WPF和WinForms.I中創建的應用程序A在WinForms中爲捕捉屏幕編寫了另一個應用程序。我面臨的問題是,應用程序A中出現的對話框沒有捕獲到屏幕中。整個屏幕被捕獲,包括對話框後面的區域,但對話框不會被捕獲。屏幕捕捉不捕獲我的應用程序中的對話框

public void CaptureScreen(string filepath) 
    { 

     string[] words = filepath.Split('\\'); 
     string newFilePath = " "; 
     foreach (string word in words) 
     { 
      if (!(word.Contains(".bmp"))) 
      { 
       newFilePath = newFilePath + word + "//"; 
      } 
      else 
      { 
       newFilePath = newFilePath + word; 
      } 


     } 

     this.WindowState = FormWindowState.Minimized; 


     Screen[] screens; 
     screens = Screen.AllScreens; 
     int noofscreens = screens.Length, maxwidth = 0, maxheight = 0; 
     for (int i = 0; i < noofscreens; i++) 
     { 
      if (maxwidth < (screens[i].Bounds.X + screens[i].Bounds.Width)) maxwidth = screens[i].Bounds.X + screens[i].Bounds.Width; 
      if (maxheight < (screens[i].Bounds.Y + screens[i].Bounds.Height)) maxheight = screens[i].Bounds.Y + screens[i].Bounds.Height; 
     } 


     var width = maxwidth; 
     var height = maxheight; 

     Point sourcePoint = Point.Empty; 
     Point destinationPoint = Point.Empty; 

     Rectangle rect = new Rectangle(0, 0, width, height); 

     Bitmap bitmap = new Bitmap(rect.Width, rect.Height); 

     Graphics g = Graphics.FromImage(bitmap); 

     // g.CopyFromScreen(sourcePoint, destinationPoint, rect.Size); 

     g.CopyFromScreen(new Point(rect.Left, rect.Top), Point.Empty, rect.Size); 

     bitmap.Save(filepath, ImageFormat.Bmp); 


     //Console.WriteLine("(width, height) = ({0}, {1})", maxx - minx, maxy - miny); 


    } 


} 

}

+0

你的代碼在哪裏捕捉屏幕區域? – 2015-02-24 05:02:05

+0

與論壇網站不同,我們不使用「謝謝」或「任何幫助表示讚賞」,或在[so]上簽名。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be -removed-from-posts)。 – 2015-02-24 05:03:22

+0

它與前景和背景窗口有關嗎? – 2015-02-24 05:29:44

回答

0
Bitmap bmpScreenshot = new Bitmap(Screen.AllScreens[1].Bounds.Width, Screen.AllScreens[1].Bounds.Height, PixelFormat.Format32bppArgb); 

      Graphics.FromImage(bmpScreenshot).CopyFromScreen(
             Screen.AllScreens[1].Bounds.X, 
             Screen.AllScreens[1].Bounds.Y, 
             0, 
             0, 
             Screen.AllScreens[1].Bounds.Size, 
             CopyPixelOperation.SourceCopy); 

      this.picExtendedModitorScreen.Image = bmpScreenshot; 
      this.picExtendedModitorScreen.Refresh(); 

放入計時器滴答事件的代碼。

我已經把代碼中的擴展屏幕1,您可以將其更改爲任何其他。