Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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.
- # 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:
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Picture and Button Demo"
- $form.ClientSize = New-Object System.Drawing.Size(400, 400)
- $picture = New-Object System.Windows.Forms.PictureBox
- $picture.Image = [System.Drawing.Image]::FromFile("C:\path\to\picture.jpg")
- $picture.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::Zoom
- $picture.Dock = [System.Windows.Forms.DockStyle]::Fill
- $button = New-Object System.Windows.Forms.Button
- $button.Text = "Show Date and Time"
- $button.Location = New-Object System.Drawing.Point(150, 150)
- $button.Size = New-Object System.Drawing.Size(100, 50)
- $button.Add_Click({
- $textbox.Text = Get-Date
- })
- $textbox = New-Object System.Windows.Forms.TextBox
- $textbox.Location = New-Object System.Drawing.Point(100, 250)
- $textbox.Size = New-Object System.Drawing.Size(200, 50)
- $textbox.ReadOnly = $true
- $form.Controls.Add($picture)
- $form.Controls.Add($button)
- $form.Controls.Add($textbox)
- $form.ShowDialog() | Out-Null
- # 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement