Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Public Class Form1
- 'Calls for png picture (screenshot)
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim userName As String = Environment.UserName
- Dim savePath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
- Dim dateString As String = Date.Now.ToString("yyyyMMddHHmmss")
- Dim captureSavePath As String = String.Format($"{{0}}\WM\{{1}}\capture_{{2}}.png", savePath, userName, dateString)
- ' This line is modified for multiple screens, also takes into account different screen size (if any)
- Dim bmp As New Bitmap(
- Screen.AllScreens.Sum(Function(s As Screen) s.Bounds.Width),
- Screen.AllScreens.Max(Function(s As Screen) s.Bounds.Height))
- Dim gfx As Graphics = Graphics.FromImage(bmp)
- ' This line is modified to take everything based on the size of the bitmap
- gfx.CopyFromScreen(SystemInformation.VirtualScreen.X,
- SystemInformation.VirtualScreen.Y,
- 0, 0, SystemInformation.VirtualScreen.Size)
- ' Oh, create the directory if it doesn't exist
- Directory.CreateDirectory(Path.GetDirectoryName(captureSavePath))
- bmp.Save(captureSavePath)
- End Sub
- 'automatically creates a desktop folder for images
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- If Not Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\WM") Then
- Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\WM")
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement