Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # *********************************************************************
- # Write a powershell script to create GUI windows with 9 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 9 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
- start-transcript
- # Create a new form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = "Numbers"
- $form.Size = New-Object System.Drawing.Size(1280,1024)
- $form.StartPosition = "CenterScreen"
- # Create 1 TextBox
- $textDisplay = New-Object System.Windows.Forms.TextBox
- $textDisplay.Location = New-Object System.Drawing.Point(10, 10)
- $textDisplay.AutoSize = 0
- $textDisplay.Multiline = 1
- $textDisplay.WordWrap = 0
- $textDisplay.width = 1400
- $textDisplay.height = 400
- $textDisplay.Font = New-Object System.Drawing.Font("Arial", 150)
- $textDisplay.ForeColor = "Green"
- $textDisplay.Text = "Press clear."
- # Create 9 buttons
- # button 1
- $button1 = New-Object System.Windows.Forms.Button
- $button1.Location = New-Object System.Drawing.Point(10, 520)
- $button1.Size = New-Object System.Drawing.Size(100, 50)
- $button1.Text = "1"
- $button1.Font = New-Object System.Drawing.Font("Arial", 15)
- $button1.BackColor = "Blue"
- $button1.ForeColor = "White"
- $button1.Add_Click({
- if ($button1.BackColor-ne "Blue") {
- $button1.BackColor = "Blue"
- $button1.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button1.BackColor = "Red"
- $button1.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button1.Text + " One"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 2
- $button2 = New-Object System.Windows.Forms.Button
- $button2.Location = New-Object System.Drawing.Point(130, 520)
- $button2.Size = New-Object System.Drawing.Size(100, 50)
- $button2.Text = "2"
- $button2.Font = New-Object System.Drawing.Font("Arial", 15)
- $button2.BackColor = "Blue"
- $button2.ForeColor = "White"
- $button2.Add_Click({
- if ($button2.BackColor-ne "Blue") {
- $button2.BackColor = "Blue"
- $button2.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button2.BackColor = "Red"
- $button2.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button2.Text + " Two"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 3
- $button3 = New-Object System.Windows.Forms.Button
- $button3.Location = New-Object System.Drawing.Point(250, 520)
- $button3.Size = New-Object System.Drawing.Size(100, 50)
- $button3.Text = "3"
- $button3.Font = New-Object System.Drawing.Font("Arial", 15)
- $button3.BackColor = "Blue"
- $button3.ForeColor = "White"
- $button3.Add_Click({
- if ($button3.BackColor-ne "Blue") {
- $button3.BackColor = "Blue"
- $button3.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button3.BackColor = "Red"
- $button3.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button3.Text + " Three"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 4
- $button4 = New-Object System.Windows.Forms.Button
- $button4.Location = New-Object System.Drawing.Point(10, 580)
- $button4.Size = New-Object System.Drawing.Size(100, 50)
- $button4.Text = "4"
- $button4.Font = New-Object System.Drawing.Font("Arial", 15)
- $button4.BackColor = "Blue"
- $button4.ForeColor = "White"
- $button4.Add_Click({
- if ($button4.BackColor-ne "Blue") {
- $button4.BackColor = "Blue"
- $button4.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button4.BackColor = "Red"
- $button4.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button4.Text + " Four"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 5
- $button5 = New-Object System.Windows.Forms.Button
- $button5.Location = New-Object System.Drawing.Point(130, 580)
- $button5.Size = New-Object System.Drawing.Size(100, 50)
- $button5.Text = "5"
- $button5.Font = New-Object System.Drawing.Font("Arial", 15)
- $button5.BackColor = "Blue"
- $button5.ForeColor = "White"
- $button5.Add_Click({
- if ($button5.BackColor-ne "Blue") {
- $button5.BackColor = "Blue"
- $button5.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button5.BackColor = "Red"
- $button5.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button5.Text + " Five"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 6
- $button6 = New-Object System.Windows.Forms.Button
- $button6.Location = New-Object System.Drawing.Point(250, 580)
- $button6.Size = New-Object System.Drawing.Size(100, 50)
- $button6.Text = "6"
- $button6.Font = New-Object System.Drawing.Font("Arial", 15)
- $button6.BackColor = "Blue"
- $button6.ForeColor = "White"
- $button6.Add_Click({
- if ($button6.BackColor-ne "Blue") {
- $button6.BackColor = "Blue"
- $button6.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button6.BackColor = "Red"
- $button6.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button6.Text + " Six"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 7
- $button7 = New-Object System.Windows.Forms.Button
- $button7.Location = New-Object System.Drawing.Point(10, 640)
- $button7.Size = New-Object System.Drawing.Size(100, 50)
- $button7.Text = "7"
- $button7.Font = New-Object System.Drawing.Font("Arial", 15)
- $button7.BackColor = "Blue"
- $button7.ForeColor = "White"
- $button7.Add_Click({
- if ($button7.BackColor-ne "Blue") {
- $button7.BackColor = "Blue"
- $button7.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button7.BackColor = "Red"
- $button7.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button7.Text + " Seven"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 8
- $button8 = New-Object System.Windows.Forms.Button
- $button8.Location = New-Object System.Drawing.Point(130, 640)
- $button8.Size = New-Object System.Drawing.Size(100, 50)
- $button8.Text = "8"
- $button8.Font = New-Object System.Drawing.Font("Arial", 15)
- $button8.BackColor = "Blue"
- $button8.ForeColor = "White"
- $button8.Add_Click({
- if ($button8.BackColor-ne "Blue") {
- $button8.BackColor = "Blue"
- $button8.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button8.BackColor = "Red"
- $button8.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button8.Text + " Eight"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 9
- $button9 = New-Object System.Windows.Forms.Button
- $button9.Location = New-Object System.Drawing.Point(250, 640)
- $button9.Size = New-Object System.Drawing.Size(100, 50)
- $button9.Text = "9"
- $button9.Font = New-Object System.Drawing.Font("Arial", 15)
- $button9.BackColor = "Blue"
- $button9.ForeColor = "White"
- $button9.Add_Click({
- if ($button9.BackColor-ne "Blue") {
- $button9.BackColor = "Blue"
- $button9.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button9.BackColor = "Red"
- $button9.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button9.Text + " Nine"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # button 0
- $button0 = New-Object System.Windows.Forms.Button
- $button0.Location = New-Object System.Drawing.Point(130, 700)
- $button0.Size = New-Object System.Drawing.Size(100, 50)
- $button0.Text = "0"
- $button0.Font = New-Object System.Drawing.Font("Arial", 15)
- $button0.BackColor = "Blue"
- $button0.ForeColor = "White"
- $button0.Add_Click({
- if ($button0.BackColor-ne "Blue") {
- $button0.BackColor = "Blue"
- $button0.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $button0.BackColor = "Red"
- $button0.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text = ""
- $textDisplay.Text = $button0.Text + " Zero"
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- # a-z key
- # Create the buttons for each letter
- $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- $buttonX = 359
- $buttonY = 520
- $buttonWidth = 70
- $buttonHeight = 70
- $i = 0
- foreach ($letter in $letters.ToCharArray()) {
- $i += 1
- $button = New-Object System.Windows.Forms.Button
- $button.Location = New-Object System.Drawing.Point($buttonX, $buttonY)
- $button.Size = New-Object System.Drawing.Size($buttonWidth, $buttonHeight)
- $button.Text = $letter
- $button.BackColor = "Blue"
- $button.ForeColor = "white"
- $button.Add_Click({
- if ($form.activeControl.BackColor -ne "Blue") {
- $form.activeControl.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $form.activeControl.Font = New-Object System.Drawing.Font("Arial", 30)
- }
- $textDisplay.Text += $form.ActiveControl.Text
- write-host $(Get-Date -Format FileDateTime)';' $textDisplay.Text
- })
- $form.Controls.Add($button)
- $buttonX += $buttonWidth + 10
- if(($i % 10) -eq 0){
- $buttonX = 359
- $buttonY += $buttonHeight + 10
- }
- }
- # Create the Sound button
- # button Sound
- $button2Sound = New-Object System.Windows.Forms.Button
- $button2Sound.Location = New-Object System.Drawing.Point(10, 700)
- $button2Sound.Size = New-Object System.Drawing.Size(100, 50)
- $button2Sound.Text = "Play Sound"
- $button2Sound.BackColor = "Blue"
- $button2Sound.ForeColor = "White"
- $button2Sound.Add_Click({
- if ($button2Sound.BackColor -ne "Blue") {
- $button2Sound.BackColor = "Blue"
- $button2Sound.Font = New-Object System.Drawing.Font("Arial", 15)
- $sound = New-Object System.Media.SoundPlayer ".\chimes.wav"
- $sound.Play()
- write-host $(Get-Date -Format FileDateTime)';' "Play .\chimes.wav"
- } else {
- $button2Sound.BackColor = "Green"
- $button2Sound.Font = New-Object System.Drawing.Font("Arial", 15)
- $sound = New-Object System.Media.SoundPlayer ".\s.wav"
- $sound.Play()
- write-host $(Get-Date -Format FileDateTime)';' "Play .\s.wav"
- }
- $textDisplay.Text = $button2Sound.Text
- })
- # Create a Image button
- # button Image
- $buttonClear = New-Object System.Windows.Forms.Button
- # $buttonClear.hide()
- $buttonClear.Text = "Clear"
- $buttonClear.BackColor = "Blue"
- $buttonClear.ForeColor = "White"
- $buttonClear.Size = New-Object System.Drawing.Size(100, 50)
- $buttonClear.Location = New-Object System.Drawing.Point(250, 700)
- # Add a click event to the button
- $buttonClear.Add_Click({
- if ($buttonClear.BackColor -ne "Blue") {
- $buttonClear.BackColor = "Blue"
- $buttonClear.Font = New-Object System.Drawing.Font("Arial", 15)
- } else {
- $buttonClear.BackColor = "Green"
- $buttonClear.Font = New-Object System.Drawing.Font("Arial", 15)
- }
- $textDisplay.Text = ""
- # Show the image
- # $image = [System.Drawing.Image]::FromFile(".\keyboard.png")
- # $pictureBox.Image = $image
- write-host $(Get-Date -Format FileDateTime)';' "clear"
- })
- # Create a picture box
- $pictureBox = New-Object System.Windows.Forms.PictureBox
- $pictureBox.Width = 994
- $pictureBox.Height = 321
- $pictureBox.Location = New-Object System.Drawing.Point(420, 520)
- # Add the button to the form
- $form.Controls.Add($button2Sound)
- # Add the button and picture box to the form
- $form.Controls.Add($buttonClear)
- $form.Controls.Add($pictureBox)
- # Add buttons to the form
- $form.Controls.Add($button1)
- $form.Controls.Add($button2)
- $form.Controls.Add($button3)
- $form.Controls.Add($button4)
- $form.Controls.Add($button5)
- $form.Controls.Add($button6)
- $form.Controls.Add($button7)
- $form.Controls.Add($button8)
- $form.Controls.Add($button9)
- $form.Controls.Add($button0)
- $form.Controls.Add($textDisplay)
- # Show the form
- $form.ShowDialog() | Out-Null
- stop-transcript
Add Comment
Please, Sign In to add comment