VB.NET 窗口截屏 (ALT+PRINTSCREEN)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2563381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET Window Screen Capture (ALT+PRINTSCREEN)
提问by Steve Thomas
I found that code somewhere and I find it quite useful but I would like to find a way to make it work so it capture only the given window target. Maybe with a processID or Window Name. Even if that window is not active.
我在某处找到了该代码,我发现它非常有用,但我想找到一种方法使其工作,以便它仅捕获给定的窗口目标。可能带有 processID 或窗口名称。即使该窗口未处于活动状态。
I do not want to make that window active but want to get a screen capture like if I was doing Alt+PrintScreen on it.
我不想使该窗口处于活动状态,但想要获得屏幕截图,就像我在其上执行 Alt+PrintScreen 一样。
Here is the code that works for full Screen Capture
这是适用于全屏捕获的代码
Private bmpScreenShot As Bitmap
Private gfxScreenshot As Graphics
bmpScreenShot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
gfxScreenshot = Graphics.FromImage(bmpScreenShot)
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
bmpScreenShot.Save(fileName, ImageFormat.Png)
I use the Visual Basic 2008 Express
我使用的是 Visual Basic 2008 Express
Thank you in advance!
先感谢您!
回答by Nagg
Look at this Capture screenshot of active window?Instead of this.Handle(current window) you may insert a handle of any other window (using WinAPIfunctions like FindWindow)
看看这个活动窗口的捕获屏幕截图?this.Handle您可以插入任何其他窗口的句柄
而不是(当前窗口)(使用WinAPI函数,例如FindWindow)
回答by Nagg
This works in vb.net2.0. I just used it. Here is the source code.
这适用于 vb.net2.0。我刚用过。 这是源代码。
Dim SC As New ScreenShot.ScreenCapture
'captures entire desktop straight to file
SC.CaptureScreenToFile("c:\accops\test\desktop2.jpg", Imaging.ImageFormat.Jpeg)
回答by Nitro
This will give you the Alt + Printscreen, showing only front most application.
这将为您提供Alt + Printscreen,仅显示最前面的应用程序。
SendKeys.Send("%{PRTSC}")
Then continue the normal way:
然后继续正常方式:
Dim Screenshot As Image = Clipboard.GetImage()
Screenshot.Save("c:\ScreenShot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
回答by T? Hùng Ph?m
Capture the active-form.
捕获活动形式。
Private Sub tsbCamera_Click(sender As Object, e As EventArgs) Handles tsbCamera.Click
Dim bm As New Bitmap(Width, Height)
DrawToBitmap(bm, New Rectangle(0, 0, Width, Height))
Dim name As String = InputBox("Name it:")
bm.Save(Application.StartupPath & "\ScreenShot\" & name & ".png", System.Drawing.Imaging.ImageFormat.Png)
End Sub
回答by Crash Matrix
The easiest way to do it, though it's a hack, is this:
最简单的方法,虽然它是一个黑客,是这样的:
SendKeys.Send("{PRTSC}")
Dim Screenshot As Image = Clipboard.GetImage()
Screenshot.Save("c:\ScreenShot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

