$form = New-Object Windows.Forms.Form
$form.text = "Chess Bored"
$form.size = New-Object Drawing.Point 625,725
$x = 25
$y = 25
$label = @() #array
For($i=0;$i -lt 8;$i++) {
For($j=0;$j -lt 8;$j++) {
$x = 25 + $i * 70
$y = 25 + $j * 80
$label = New-Object Windows.Forms.Label
$label.Location = New-Object Drawing.Point $x,$y
$label.Size = New-Object Drawing.Point 70,80
$label.Text = "($i,$j)"
$label.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$label.BackColor = $c
$label.add_Click({Write-Host "$Label.Text"})
$form.controls.add($label)
}
}
$form.ShowDialog()
The above code does create a 8x8 set of labels (0,0) .. (7,7) but when I click on a label I get only "(7,7)". and yes I don't know forms. so help me please, I would like the Add_Click function to return the label text (x,y) associated with the one I clicked.