Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Write a powershell script to create GUI windows with 4 click blue buttons inside. When click one of the buttons , the button color change from blue to red.
- # Here's a PowerShell script that creates a GUI window with 4 blue buttons inside. When you click one of the buttons, the button color changes from blue to red:
- # powershell
- Add-Type -AssemblyName System.Windows.Forms
- # Create a new form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Button Demo"
- $form.Size = New-Object System.Drawing.Size(300, 300)
- $form.StartPosition = "CenterScreen"
- # Create 4 buttons
- $button1 = New-Object System.Windows.Forms.Button
- $button1.Location = New-Object System.Drawing.Point(20, 20)
- $button1.Size = New-Object System.Drawing.Size(100, 50)
- $button1.Text = "Button 1"
- $button1.BackColor = "Blue"
- $button1.Add_Click({
- if($button1.BackColor -ne "Blue")
- {
- $button1.BackColor = "Blue"
- }
- else
- {
- $button1.BackColor = "Red"
- }
- })
- $button2 = New-Object System.Windows.Forms.Button
- $button2.Location = New-Object System.Drawing.Point(140, 20)
- $button2.Size = New-Object System.Drawing.Size(100, 50)
- $button2.Text = "Button 2"
- $button2.BackColor = "Blue"
- $button2.Add_Click({
- if($button2.BackColor -ne "Blue")
- {
- $button2.BackColor = "Blue"
- }
- else
- {
- $button2.BackColor = "Red"
- }
- })
- $button3 = New-Object System.Windows.Forms.Button
- $button3.Location = New-Object System.Drawing.Point(20, 80)
- $button3.Size = New-Object System.Drawing.Size(100, 50)
- $button3.Text = "Button 3"
- $button3.BackColor = "Blue"
- $button3.Add_Click({
- if($button3.BackColor -ne "Blue")
- {
- $button3.BackColor = "Blue"
- }
- else
- {
- $button3.BackColor = "Red"
- }
- })
- $button4 = New-Object System.Windows.Forms.Button
- $button4.Location = New-Object System.Drawing.Point(140, 80)
- $button4.Size = New-Object System.Drawing.Size(100, 50)
- $button4.Text = "Button 4"
- $button4.BackColor = "Blue"
- $button4.Add_Click({
- if($button4.BackColor -ne "Blue")
- {
- $button4.BackColor = "Blue"
- }
- else
- {
- $button4.BackColor = "Red"
- }
- })
- # Add buttons to the form
- $form.Controls.Add($button1)
- $form.Controls.Add($button2)
- $form.Controls.Add($button3)
- $form.Controls.Add($button4)
- # Show the form
- $form.ShowDialog() | Out-Null
- # This script uses the `System.Windows.Forms` assembly to create a new form and 4 buttons. Each button is given a blue background color and an event handler that changes the background color to red when the button is clicked. Finally, the buttons are added to the form and the form is displayed using the `ShowDialog()` method.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement