Advertisement
bazmikel

POWERSHELL | ZAD3LAB01

Apr 7th, 2020
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -AssemblyName System.Windows.Forms
  2. $Window = New-Object System.Windows.Forms.Form
  3. $Window.Text = "Laboratorium 3.1"
  4. $Window.Width = 800
  5. $Window.Height = 600
  6. $Window.AutoScale=$false
  7. $WindoW.AllowDrop=$false
  8.  
  9.  
  10. $WindowToChooseColor = New-Object System.Windows.Forms.ColorDialog
  11. $WindowToChooseColor.FullOpen=1
  12.  
  13.  
  14. $WindowToChooseFont = New-Object System.Windows.Forms.FontDialog
  15. $WindowToChooseFont.MaxSize = 18
  16.  
  17.  
  18. $Text = New-Object System.Windows.Forms.Label
  19. $Text.Text = "Wprowadz liczby do wykonania operacji: "
  20. $Text.Font = New-Object System.Drawing.Font("Times New Roman", 14)
  21. $Text.Width = 400
  22. $Text.Height = 25
  23. $Text.Location = New-Object System.Drawing.Size(255, 20)
  24. $Text.ForeColor = "Black"
  25.  
  26.  
  27. $Komunikat = New-Object System.Windows.Forms.Label
  28. $Komunikat.Text = ""
  29. $Komunikat.Width = 450
  30. $Komunikat.Font = New-Object System.Drawing.Font("Times New Roman", 14)
  31. $Komunikat.Location = New-Object System.Drawing.Size(270, 320)
  32. $Komunikat.ForeColor = "Red"
  33. $Window.Controls.Add($Komunikat)
  34.  
  35. $TextBox1 = New-Object System.Windows.Forms.TextBox
  36. $TextBox1.Location = New-Object System.Drawing.Size(300, 60)
  37. $TextBox1.Width = 200
  38. $TextBox1.Height = 30
  39. $TextBox1.Text = "wartosc 1"
  40.  
  41.  
  42. $TextBox2 = New-Object System.Windows.Forms.TextBox
  43. $TextBox2.Location = New-Object System.Drawing.Size(300, 90)
  44. $TextBox2.Width = 200
  45. $TextBox2.Height = 30
  46. $TextBox2.Text = "wartosc 2"
  47.  
  48.  
  49. $Result = New-Object System.Windows.Forms.Label
  50. $Result.Text = "Wynik:"
  51. $Result.Width = 100
  52. $Result.Height = 70
  53. $Result.Font = New-Object System.Drawing.Font("Times New Roman", 18)
  54. $Result.Location = New-Object System.Drawing.Size(330, 120)
  55. $Window.Controls.Add($Result)
  56.  
  57. $Result1 = New-Object System.Windows.Forms.Label
  58. $Result1.Text = " 0 "
  59. $Result.Height = 70
  60. $Result1.Font = New-Object System.Drawing.Font("Times New Roman", 18)
  61. $Result1.Location = New-Object System.Drawing.Size(440, 120)
  62.  
  63.  
  64.  
  65. $ColorButton = New-Object System.Windows.Forms.Button
  66. $ColorButton.Text = "Kolor"
  67. $ColorButton.Location = New-Object System.Drawing.Size(350, 200)
  68. $ColorButton.BackColor = "White"
  69. $ColorButton.width = 80
  70. $ColorButton.Add_Click(
  71.     {$WindowToChooseColor.ShowDialog();
  72.     $Window.BackColor= $WindowToChooseColor.Color
  73.     }
  74. ); #closes window after clicking
  75.  
  76. $FontButton = New-Object System.Windows.Forms.Button
  77. $FontButton.Text = "Czcionka"
  78. $FontButton.BackColor = "White"
  79. $FontButton.Location = New-Object System.Drawing.Size(350, 225)
  80. $FontButton.width = 80
  81. $FontButton.Add_Click(
  82.     {
  83.     $WindowToChooseFont.ShowDialog()
  84.     $Result.Font = $WindowToChooseFont.Font
  85.     $Result1.Font = $WindowToChooseFont.Font
  86.     }
  87. )
  88.  
  89.  
  90.  
  91. $SumButton = New-Object System.Windows.Forms.Button
  92. $SumButton.Text = "Suma"
  93. $SumButton.BackColor = "White"
  94. $SumButton.Location = New-Object System.Drawing.Size(315, 270)
  95. $SumButton.Width = 45
  96. $SumButton.Add_Click({
  97.  
  98.  
  99. obliczSume
  100.  
  101. }
  102. )
  103.  
  104. $MulButton = New-Object System.Windows.Forms.Button
  105. $MulButton.Text = "Iloczyn"
  106. $MulButton.Location = New-Object System.Drawing.Size(365, 270)
  107. $MulButton.Width = 55
  108. $MulButton.BackColor = "White"
  109. $MulButton.Add_Click({
  110.     obliczIloczyn
  111. })
  112. $DivButton = New-Object System.Windows.Forms.Button
  113. $DivButton.Text = "Iloraz"
  114. $DivButton.BackColor = "White"
  115. $DivButton.Location = New-Object System.Drawing.Size(425, 270)
  116. $DivButton.Width = 45
  117. $DivButton.Add_Click({
  118.     obliczIloraz
  119. })
  120.  
  121. $SubButton = New-Object System.Windows.Forms.Button
  122. $SubButton.Text = "Roznica"
  123. $SubButton.BackColor = "White"
  124. $SubButton.Location = New-Object System.Drawing.Size(363, 296)
  125. $SubButton.Width = 60
  126. $SubButton.Add_Click({
  127. obliczRoznice
  128. })
  129.  
  130. function obliczSume(){
  131.  
  132.    
  133.         Try{
  134.         $Result1.Text = [System.Convert]::ToInt32($TextBox1.Text) + [System.Convert]::ToInt32($TextBox2.Text)
  135.         $Komunikat.Text = ""
  136.         }
  137.         Catch{
  138.         $Result1.Text = "Błąd"
  139.         $Komunikat.Text = "Musisz wprowadzic obe liczby"
  140.     }
  141.    
  142.  
  143.  
  144. }
  145.  
  146.  
  147.  
  148.  
  149. function obliczRoznice(){
  150.  
  151.     Try{
  152.         $Result1.Text = [System.Convert]::ToInt32($TextBox1.Text) - [System.Convert]::ToInt32($TextBox2.Text)
  153.         $Komunikat.Text = ""
  154.         }
  155.         Catch{
  156.         $Result1.Text = "Błąd"
  157.         $Komunikat.Text = "Musisz wprowadzic obe liczby"
  158.     }
  159.    
  160. }
  161.  
  162.  
  163. function obliczIloczyn(){
  164.  
  165.     Try{
  166.         $Result1.Text = [System.Convert]::ToInt32($TextBox1.Text) * [System.Convert]::ToInt32($TextBox2.Text)
  167.         $Komunikat.Text = ""
  168.         }
  169.         Catch{
  170.         $Result1.Text = "Błąd"
  171.         $Komunikat.Text = "Musisz wprowadzic obe liczby"
  172.     }
  173.  
  174.    
  175. }
  176. function obliczIloraz(){
  177.    
  178.    
  179.     Try{
  180.     If([System.Convert]::ToInt32($TextBox2.Text) -eq 0){
  181.         $Komunikat.Text = "Nie mozna dzielic przez 0"
  182.         $Result1.Text = "Bład"
  183.         }
  184.     else{
  185.     $Result1.Text = [System.Convert]::ToInt32($TextBox1.Text) / [System.Convert]::ToInt32($TextBox2.Text)
  186.     $Komunikat.Text = ""
  187.     }
  188.     }
  189.     Catch{
  190.         $Result1.Text = "Błąd"
  191.         $Komunikat.Text = "Musisz wprowadzic obe liczby"
  192.     }
  193.    
  194. }
  195.  
  196.  
  197. $window.Controls.Add($Text)
  198. $Window.Controls.Add($fontButton)
  199. $Window.Controls.Add($Result1)
  200. $Window.Controls.Add($TextBox1)
  201. $Window.Controls.Add($TextBox2)
  202. $Window.Controls.Add($ColorButton)
  203. $Window.Controls.Add($SumButton)
  204. $Window.Controls.Add($MulButton)
  205. $Window.Controls.Add($DivButton)
  206. $Window.Controls.Add($SubButton)
  207. $Window.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement