Advertisement
Rythorian

Untitled

Nov 24th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | Source Code | 0 0
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4. 'Calls for png picture (screenshot)
  5. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  6. Dim userName As String = Environment.UserName
  7. Dim savePath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
  8. Dim dateString As String = Date.Now.ToString("yyyyMMddHHmmss")
  9. Dim captureSavePath As String = String.Format($"{{0}}\WM\{{1}}\capture_{{2}}.png", savePath, userName, dateString)
  10. ' This line is modified for multiple screens, also takes into account different screen size (if any)
  11. Dim bmp As New Bitmap(
  12. Screen.AllScreens.Sum(Function(s As Screen) s.Bounds.Width),
  13. Screen.AllScreens.Max(Function(s As Screen) s.Bounds.Height))
  14. Dim gfx As Graphics = Graphics.FromImage(bmp)
  15. ' This line is modified to take everything based on the size of the bitmap
  16. gfx.CopyFromScreen(SystemInformation.VirtualScreen.X,
  17. SystemInformation.VirtualScreen.Y,
  18. 0, 0, SystemInformation.VirtualScreen.Size)
  19. ' Oh, create the directory if it doesn't exist
  20. Directory.CreateDirectory(Path.GetDirectoryName(captureSavePath))
  21. bmp.Save(captureSavePath)
  22.  
  23. End Sub
  24. 'automatically creates a desktop folder for images
  25. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  26. If Not Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\WM") Then
  27. Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\WM")
  28. End If
  29.  
  30. End Sub
  31. End Class
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement