Advertisement
wetyukmnbxc

Untitled

Mar 8th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Write a powershell script to create a GUI. In the GUI, show 1 picture and 1 button overlapped with the picture. When the button is clicked, the textbox display the current datetime.
  2.  
  3.  
  4. # Here's a PowerShell script that creates a GUI with a picture and a button overlaid on the picture. When the button is clicked, the current date and time is displayed in a text box:
  5.  
  6. Add-Type -AssemblyName System.Windows.Forms
  7. Add-Type -AssemblyName System.Drawing
  8. $form = New-Object System.Windows.Forms.Form
  9. $form.Text = "Picture and Button Demo"
  10. $form.ClientSize = New-Object System.Drawing.Size(400, 400)
  11. $picture = New-Object System.Windows.Forms.PictureBox
  12. $picture.Image = [System.Drawing.Image]::FromFile("C:\path\to\picture.jpg")
  13. $picture.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
  14. $picture.Dock = [System.Windows.Forms.DockStyle]::Fill
  15. $button = New-Object System.Windows.Forms.Button
  16. $button.Text = "Show Date and Time"
  17. $button.Location = New-Object System.Drawing.Point(150, 150)
  18. $button.Size = New-Object System.Drawing.Size(100, 50)
  19. $button.Add_Click({
  20. $textbox.Text = Get-Date
  21. })
  22. $textbox = New-Object System.Windows.Forms.TextBox
  23. $textbox.Location = New-Object System.Drawing.Point(100, 250)
  24. $textbox.Size = New-Object System.Drawing.Size(200, 50)
  25. $textbox.ReadOnly = $true
  26. $form.Controls.Add($picture)
  27. $form.Controls.Add($button)
  28. $form.Controls.Add($textbox)
  29. $form.ShowDialog() | Out-Null
  30.  
  31.  
  32. # Replace "C:\path\to\picture.jpg" with the path to your own picture. When the button is clicked, `Get-Date` is called to retrieve the current date and time, which is then displayed in the text box.
  33.  
  34.  
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement