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

JooClops commented: The most Awesome guy in the world<<<< +1

Thanks again Jerry :P
few questions:
try.....finally.... works on Console app as well? I've never heard of it! if i understood it right , it's kinda useful, no matter what happens in try, they finally will occur in the " finally" :X.
second question:
ok nvm xD there was a little problem but i fixed that :P
Oh, and i couldn't open the zip ,even with a zip opener..
Basically It's finished :} just some addons such as the randomizer :} I can;t wait to take a look and see how it looks like! And I'm going to make an "instructions button" so it will pop up a windows with instructions :P I think i can do this by my own with the new things I have learned :>
Thank You,
JooClops

Yes Try..Catch and Try..Finally are basic code blocks available in all projects for c#.

I will find another way to send you the zip file. I made a few changes so that the numbers are centered in the panel cell, and a randomizer populates some of the cells. A future option to consider is to allow the user to select the difficulty level so that you can control the number of values the computer places on the screen.

I think you will find it interesting.

// Jerry

This is so beautiful!
I didn't expect this at all XD It looks like a real soduku ,and man what an organized code! I'll never reach that level,My codes are always messy,maybe it comes with experience :}
Thank you int 10000000th time :) I wish you just the best!!
now for the questions :P :
I understood most of the code(and i was happy i did!),the part had the most difficult time is :

lbl.ForeColor = lbl.AllowDrop ? Color.Blue : Color.Black; // Set hard numbers Black, and user numbers Blue
//could you explain how does it work? is it like if allowdrop=true then -->blue else black? I've never seen this kind of thing, so simple and beautiful!

                            passes = 0;                                 // Going to test to see if this is a good value. But limit it to 9 tries.
                            while (passes++ < 9 && !PassChecks())       // Check to see if this number in this position is okay
                            {
                                value = rd.Next(1, 9);                  // Now we want a good number so min is 1, and max is 9
                                lbl.Text = value.ToString();            // Set the value as text
                                _mat[row, col] = value;                 // set the Matrix value, go back and test, if we fall out of the loop
                            }                                           // then either it passed,
                            if (passes >= 9)                            // or failed, in which case we set it to nothing and the matrix to 0
                            {
                                lbl.Text = string.Empty;
                                _mat[row, col] = 0;
                            }
                        }

//comment after the code:

this part was the hardest for me to understand and I'm still confused,the if passes>=9, the max value of passes will be 9 from the while loop, so is there a reason its passes>=9 and not passes==9?maybe i missed something... oh in second thought i understand everything else in the code above now XD
I really liked the using of Passchecks method , and sending true to the row\col\square checking method so it identifies as called from "Clear" :X just awesome!

I'm still amazed and shocked! this is like a real game!
Now that I obtained some descent knowledge(not that different from console app as i thought) in the summer I'll make my own project,"Towers of Hanoi" I'll call it(like the legend if you heard), cause next year there will be a project that will give me 5 more units(units are calculated by the university, units*the grade) but it's huge one,Which is high level project.So I'll have to practice, and it's just cool and beautiful!!!
I'm so happy :}
So thank You for everything!

JooClops

P.S
Forgot one thing,
Can i just brush it so it looks like this :
[img=http://img216.imageshack.us/img216/5934/95455806.jpg]
is it difficult?

lbl.ForeColor = lbl.AllowDrop ? Color.Blue : Color.Black;
That is what we call short cut code. It comes from the old days when we had the IIF statement. your assumption is correct, the first segment must equate to a boolean expression, the second is the value to deliver when the boolean is true. The third segment is the else value.

Passes... This is a triggered kill point. If the validity checks fail after nine attempts, then just leave the target blank and move on. Without this, you could find yourself in an endless loop, or atleast a very long running loop.
Most of the time, the PassChecks() will return true, and it only goes into the loop when a conflict is detected.
Anytime you have a loop construct ALWAYS give your code a way of timing out or escaping the loop. If it came out of the loop and the trigger point was reached, then blank the text and array for this position.

How the code works is that if the randomizer gave us a value in range, we start testing (makes sure that the value being placed will not violate Soduko rules off the bat, the job of PassChecks). If it fails the test, then we give it another number to try. Stop trying after 9 passes.

BTW, to increase or decrease the difficulty level of the game, you can just set the rd.Next in the line above this section (currently 18).
This number effects the amount of numbers that are placed onto the screen. Increase or decrease the value to adjust the difficulty level.

Yes, I was thinking the same thing about the color lines to segment the squares. Yes it can be done using the Panel's Paint event. You can also set the background image of the tablelayout component to some nice sutle half transparent image to give it a pro look. Even randomize the images.. that would be neat.

Now you are getting into the fun stuff.... Graphics are cool stuff, but frustrating to get started in. Working with graphics will open up your eyes to what is really going on under the hood.

Have Fun,
Jerry

Okay,
You wanted lines... You got Lines :)
Add this Paint event handler to your panel's Paint event.

private void panel_Paint(object sender, PaintEventArgs e)
        {
            int rowLineOffset = panel.Height / 3;
            int colLineOffset = panel.Width / 3;
            Pen pen = new Pen(Brushes.Red);
            pen.Width = 3;
            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            for (int i = 1; i < 3; i++)
            {
                e.Graphics.DrawLine(pen, new Point(3, i * rowLineOffset - i * 2), new Point(panel.Width -3, i * rowLineOffset - i * 2));
                e.Graphics.DrawLine(pen, new Point(i * colLineOffset - i * 2, 3), new Point(i * colLineOffset - i * 2, panel.Height -3));
            }
            pen.Dispose();
        }

This is so Great :}
It's finished! I'll read up on the web about pictures and stuff.
I'm a bit jealous of your knowledge :< well....one day ...one day...:)
just a question from curiosity, can i work with multiply forms? lets say i have Form1 that has 2 options, enter the form 2 or form 3 , and after i enter form 2 i can go back to form 1 with button click?

Thank you for everything,I appreciate you devoted your free time for me , can't express how thankful I am.

JooClops

Welcome, its nice to be able to help and work on something other than the complex code I typically deal with everyday in my job.

Yes you can have multiple forms and navigate between them using buttons, etc.

Have fun,
// Jerry

commented: Can't stop thanking You +1

Great! thanks :} i cant imagine how complex the codes you're dealing with ,maybe in the future I'll have to deal with them as well :P
well I'm marking this thread solved.
so thanks again.

JooClops

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.