Hello,windows applications,help please

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Hello,windows applications,help please

 
1
  #31
Apr 5th, 2009
Okay

Got the project.
Below is the Clear button event handler.
An explanation follows.

  1. private void btnclr_Click(object sender, EventArgs e)
  2. {
  3. Label lbl;
  4. int num;
  5. string tag;
  6. try
  7. {
  8. Enabled = false;
  9. this.Cursor = Cursors.WaitCursor;
  10. panel.SuspendLayout();
  11. foreach (Control cntrl in panel.Controls)
  12. {
  13. lbl = cntrl as Label;
  14. if (lbl != null)
  15. {
  16. tag = lbl.Tag as string;
  17. num = 1 + Convert.ToInt32(tag.Split('|')[1]);
  18. lbl.Text = num.ToString();
  19. }
  20. }
  21. for (int i = 0; i < 9; i++)
  22. for (int j = 0; j < 9; j++)
  23. _mat[i, j] = i;
  24. }
  25. finally
  26. {
  27. this.Cursor = Cursors.Default;
  28. Enabled = true;
  29. panel.ResumeLayout(true);
  30. }
  31. }

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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: JooClops is an unknown quantity at this point 
Solved Threads: 0
JooClops JooClops is offline Offline
Light Poster

Re: Hello,windows applications,help please

 
0
  #32
Apr 6th, 2009
Thanks again Jerry
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" .
second question:
ok nvm xD there was a little problem but i fixed that
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 I think i can do this by my own with the new things I have learned :>
Thank You,
JooClops
Last edited by JooClops; Apr 6th, 2009 at 6:25 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Hello,windows applications,help please

 
0
  #33
Apr 6th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: JooClops is an unknown quantity at this point 
Solved Threads: 0
JooClops JooClops is offline Offline
Light Poster

Re: Hello,windows applications,help please

 
0
  #34
Apr 6th, 2009
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 :
I understood most of the code(and i was happy i did!),the part had the most difficult time is :
  1. lbl.ForeColor = lbl.AllowDrop ? Color.Blue : Color.Black; // Set hard numbers Black, and user numbers Blue
  2. //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!
  3.  
  4. passes = 0; // Going to test to see if this is a good value. But limit it to 9 tries.
  5. while (passes++ < 9 && !PassChecks()) // Check to see if this number in this position is okay
  6. {
  7. value = rd.Next(1, 9); // Now we want a good number so min is 1, and max is 9
  8. lbl.Text = value.ToString(); // Set the value as text
  9. _mat[row, col] = value; // set the Matrix value, go back and test, if we fall out of the loop
  10. } // then either it passed,
  11. if (passes >= 9) // or failed, in which case we set it to nothing and the matrix to 0
  12. {
  13. lbl.Text = string.Empty;
  14. _mat[row, col] = 0;
  15. }
  16. }
  17.  
  18. //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" 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?
Last edited by JooClops; Apr 6th, 2009 at 3:15 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Hello,windows applications,help please

 
0
  #35
Apr 6th, 2009
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
Last edited by JerryShaw; Apr 6th, 2009 at 7:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Hello,windows applications,help please

 
0
  #36
Apr 6th, 2009
Okay,
You wanted lines... You got Lines
Add this Paint event handler to your panel's Paint event.

  1. private void panel_Paint(object sender, PaintEventArgs e)
  2. {
  3. int rowLineOffset = panel.Height / 3;
  4. int colLineOffset = panel.Width / 3;
  5. Pen pen = new Pen(Brushes.Red);
  6. pen.Width = 3;
  7. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  8. for (int i = 1; i < 3; i++)
  9. {
  10. e.Graphics.DrawLine(pen, new Point(3, i * rowLineOffset - i * 2), new Point(panel.Width -3, i * rowLineOffset - i * 2));
  11. e.Graphics.DrawLine(pen, new Point(i * colLineOffset - i * 2, 3), new Point(i * colLineOffset - i * 2, panel.Height -3));
  12. }
  13. pen.Dispose();
  14. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: JooClops is an unknown quantity at this point 
Solved Threads: 0
JooClops JooClops is offline Offline
Light Poster

Re: Hello,windows applications,help please

 
0
  #37
Apr 7th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Hello,windows applications,help please

 
1
  #38
Apr 7th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: JooClops is an unknown quantity at this point 
Solved Threads: 0
JooClops JooClops is offline Offline
Light Poster

Re: Hello,windows applications,help please

 
0
  #39
Apr 7th, 2009
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
well I'm marking this thread solved.
so thanks again.

JooClops
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC