Sub Button1_Click
TakeScreenshot(File.Combine(File.DirApp, "1.png"), MainForm.WindowLeft, MainForm.WindowTop, _
MainForm.WindowLeft + MainForm.WindowWidth, MainForm.WindowTop + MainForm.WindowHeight)
End Sub
Public Sub TakeScreenshot (OutputFile As String, Left As Int, Top As Int, Right As Int, Bottom As Int)
Dim script As String = $"
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB(${Left}, ${Top}, ${Right}, ${Bottom})
screenshot $bounds "${OutputFile}"
"$
Wait For (PowerShellScript(script)) Complete (Result As ShellSyncResult)
If Result.ExitCode = 0 Then
PowerShellScript(OutputFile) 'show the screenshot
End If
End Sub