Currently i am trying to write a chess program within vb. The initial problem i am having is using a handler to select a square and then another square, this is mimicking the process of selecting a piece to move and then a place to move it to. in the code below i have added a handler so that each panel can be clicked along with a second panel but the panel its self is selected rather than the board array that i want to be selected. i have tried using board.click bu this does not seem to work as board is a 2d array. My question is how do i pass a board value into a subroutine using addhandler rather than just the panel.
Public Class Form1 Dim board(7, 7) As Panel Dim pointer As Integer = 0 Dim first As Panel Dim second As Panel Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load loadboard() End Sub Sub loadboard() For x = 0 To 7 For y = 0 To 7 Dim pnl As New Panel With pnl If x Mod 2 = y Mod 2 Then .BackColor = Color.White ElseIf x Mod 2 <> y Mod 2 Then .BackColor = Color.Brown End If .BorderStyle = BorderStyle.FixedSingle .Location = New Point(55 * x, 55 * y) .Size = New Size(55, 55) End With board(x, y) = pnl Me.Controls.Add(pnl) AddHandler pnl.Click, AddressOf pnl_click Next Next End Sub Sub pnl_click(sender As Object, e As EventArgs) Dim clickedpnl As Panel = DirectCast(sender, Panel) clickedpnl.BackColor = Color.Yellow If pointer = 0 Then first = clickedpnl pointer = 1 Else second = clickedpnl pointer = 0 End If End Sub End Class