PoshCode Logo PowerShell Code Repository

Difference between
modified post 6807 by HeyNow on Mon 20th Mar 18:29 and
original post 6436 by silvia on Fri 1st Jul 11:28
Showold version | new version | both versions

    
11
function frmMain_Show {
22
  Add-Type -Assembly System.Windows.Forms
33
  [Windows.Forms.Application]::EnableVisualStyles()
55
  $ico = [Drawing.Icon]::ExtractAssociatedIcon(($PSHome + '\powershell.exe'))
7-
  $cur = $false #users switch
7+
  $script:cur = $false #users switch
88
  $btn = New-Object "Windows.Forms.Button[,]" 3, 3
1010
  $frmMain = New-Object Windows.Forms.Form
1111
  $btnPlay = New-Object Windows.Forms.Button
1212
  #
1313
  #btnPlay
1414
  #
1515
  $btnPlay.Location = New-Object Drawing.Point(78, 225)
1616
  $btnPlay.Text = "New Play"
1717
  $btnPlay.Add_Click({
18-
    $cur = $false
18+
    $script:cur = $false
1919
    $btn | % {$_.Text = [String]::Empty}
2020
  })
2121
  #
2222
  #frmMain
2323
  #
2424
  $frmMain.ClientSize = New-Object Drawing.Size(231, 260)
2525
  $frmMain.Controls.Add($btnPlay)
2626
  $frmMain.FormBorderStyle = [Windows.Forms.FormBorderStyle]::FixedSingle
2727
  $frmMain.Icon = $ico
2828
  $frmMain.MainMenuStrip = $mnuMain
2929
  $frmMain.MaximizeBox = $false
3030
  $frmMain.MinimizeBox = $False
3131
  $frmmain.StartPosition = [Windows.Forms.FormStartPosition]::CenterScreen
3232
  $frmMain.Text = "Tic Tac Toe"
3333
  $frmMain.Add_Load({
3434
    for ($i = 0; $i -lt 3; $i++) {
3535
      for ($j = 0; $j -lt 3; $j++) {
3636
        $btn[$i, $j] = New-Object Windows.Forms.Button
3737
        $btn[$i, $j].Parent = $this
3838
        $btn[$i, $j].Left = 10 + $j * 70
3939
        $btn[$i, $j].Top = 10 + $i * 70
4040
        $btn[$i, $j].Size = New-Object Drawing.Size(70, 70)
4141
        $btn[$i, $j].Font = New-Object Drawing.Font("Microsoft Sans Serif", 27, [Drawing.FontStyle]::Bold)
4242
        $btn[$i, $j].Add_Click({
4343
          if ([String]::IsNullOrEmpty($this.Text)) {
44-
            switch ($cur) {
44+
            switch ($script:cur) {
4545
              $true {
4646
                $this.ForeColor = [Drawing.Color]::Crimson
4747
                $this.Text = "O"
48-
                $cur = $false
48+
                $script:cur = $false
4949
              }
5050
              default {
5151
                $this.ForeColor = [Drawing.Color]::DarkGreen
5252
                $this.Text = "X"
53-
                $cur = $true
53+
                $script:cur = $true
5454
              }
5555
            } #switch
5656
          }
5757
        }) #btnX_Click
5858
      } #for
5959
    } #for
6060
  })
6262
  [void]$frmmain.ShowDialog()
6363
}
6565
frmMain_Show

ContributeMost Recent Contributions (feed)

Contribute ... Next Page