Okay
Got the project.
Below is the Clear button event handler.
An explanation follows.
private void btnclr_Click(object sender, EventArgs e)
{
Label lbl;
int num;
string tag;
try
{
Enabled = false;
this.Cursor = Cursors.WaitCursor;
panel.SuspendLayout();
foreach (Control cntrl in panel.Controls)
{
lbl = cntrl as Label;
if (lbl != null)
{
tag = lbl.Tag as string;
num = 1 + Convert.ToInt32(tag.Split('|')[1]);
lbl.Text = num.ToString();
}
}
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
_mat[i, j] = i;
}
finally
{
this.Cursor = Cursors.Default;
Enabled = true;
panel.ResumeLayout(true);
}
}
First it declares a few working variables.
Next we place the code into a Try...finally, for a number of reasons, but primarily because we are going to set the cursor to a waitCursor ( because working with longer iterations should do this).
And we are going to Disable the form by setting the Enable to false (lock the user out so they can not mess with what we are doing).
Disable the layout panel so that it will not flicker and slow us down with its internal rendering.
and finally because we want to make sure all things will be turned back on no matter what happens in the code.
Inside of the working code, we iterate through all of the labels of interest within the layout panel. We get their j value from their Tag, add one to it (because it is zero based for addressing purposes).
Last thing is to reset the _mat array to their original values.
In the finally code block, we just turn things back on for the user.
// Jerry