Bonjour, voila quand je lance mon programme il me met "L'exception System.StackOverflowException n'a pas été gérée"

En fait ce qui est bizard c'est qu'il n'y a pa de boucle infini....
Voila le code avec en rouge et gras la ou il bug :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace sudoku
{
    public partial class Form1 : Form
    {
       public string[,] tabSudo;
       public MaskedTextBox[,] tabMask;
     

        public Form1()
        {


            InitializeComponent();
            string[,] tabSudo = new string[10, 10];                // l'emplacement 0 n'est jamais utilisé, car il n'existe pa de chiffre 0 ds un sudoku
            MaskedTextBox[,] tabMask = new MaskedTextBox[10, 10]; // l'emplacement 0 n'est jamais utilisé, car il n'existe pa de chiffre 0 ds un sudoku
         
            creerTab(tabMask);
            hasard(tabMask);
            
           
        }



        public void creerTab(MaskedTextBox[,] tabMask) // creation du tableau 9x9 en masked text box
        {

            
            int x;
            int y;
            int xx = 3;
            int yy = 4;

            
            
            for (x = 1; x <= 9; x++)
            {
                for (y = 1; y <= 9; y++)
                {
                   
                  tabMask[x, y] = new MaskedTextBox();
                  tabMask[x, y].Mask = "9";
                  tabMask[x, y].Name = "box" + x + y;
                  tabMask[x, y].Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                  tabMask[x, y].TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
                  tabMask[x, y].Location = new System.Drawing.Point(xx, yy);
                  tabMask[x, y].Size = new System.Drawing.Size(54, 47);
                  panel1.Controls.Add(tabMask[x, y]);


                   
                    xx += 61; // augmentation des pixel pour le drawing


                    if (y == 9) { xx = 3; } // on repasse a la ligne

                }
                yy += 53;
            }

            this.tabMask = tabMask;
           
        }




        public void hasard(MaskedTextBox[,] tabMask) //creation des 1er chiffre mis au hasard 
        {

           
            string ch1;
            string ch2;
            string ch3;
       

            int iCh1;
            int iCh2;
            int x;
            for (x = 0; x < 5; x++)
            {
                ch1 = creerMilli(1, 1);
                ch2 = creerMilli(1, 1);

                ch3 = creerMilli(0, 1);

                while (verifChiffre(ch1, ch2, ch3) == true)
                {
                    ch1 = creerMilli(1, 1);
                    ch2 = creerMilli(1, 1);

                    ch3 = creerMilli(0, 1);
                }


                iCh1 = Convert.ToInt16(ch1);
                iCh2 = Convert.ToInt16(ch2);

                tabMask[iCh1, iCh2].Text = ch3; // on place au hasard un 1er chiffre
                tabMask[iCh1, iCh2].Enabled = false;


            }


  

            this.tabMask = tabMask;
        }




        public string creerMilli(int x, int y)
        {
            string chi;


                chi = DateTime.Now.Millisecond.ToString();

                while (x == 2 && chi.Length > 2)
                {
                    chi = DateTime.Now.Millisecond.ToString();
                    
                }
            

                while (x > 0 && chi.Length == 1)
                {
                    chi = DateTime.Now.Millisecond.ToString();

                }

                if (chi.Length == 1 && x > 1)
                {
                    return chi;
                }

                chi = chi.Substring(x, y);

                if (chi == "0")
                {
                   chi = creerMilli(x, y);
                }
                


               
            return chi;
        }



        public string verifCreCh(string unChiffre) // creer un nouveau chiffre au hasard en vérifian kil n'est pas egal a unChiffre
        {
            string c; 

            c = creerMilli(1,1);

            while(unChiffre == c)
            {
                c = creerMilli(1, 1);
            }

            return c;

        }


        public bool verifCol(string unChiffre, string colonne)
        {
            int i;
            int col = Convert.ToInt16(colonne);

            for (i = 1; i < 10; i++)
            {
                if (tabMask[col, i].Text == unChiffre && tabMask[col, i].Text != "")
                {
                    return true;
                }
                
            }

            return false;


        }


        public bool verifLigne(string unChiffre, string ligne)
        {
            int i;
            int lign = Convert.ToInt16(ligne);

            for (i = 1; i <= 9; i++)
            {
                if (tabMask[lign, i].Text == unChiffre && tabMask[lign, i].Text != "")
                {
                    return true;
                }

            }

            return false;


        }

        public bool verifCarre(string unChiffre, string ligne, string colonne) // verifie kun chiffre n'existe pas ds un carree
        {
            int x = Convert.ToInt16(ligne);
            int y = Convert.ToInt16(colonne);
            int i;
            int a;
         

            if (x <= 3 && y <= 3) //  carree = 1;
            {
               
                for(i = 1; i <=3; i++)
                {
                    for (a = 1; a <= 3; a++ )
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

            if (x <= 3 && y > 3 && y <= 6)//  carree = 2;
            {

                for (i = 1; i <= 3; i++)
                {
                    for (a = 4; a <= 6; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

            if (x <= 3 && y > 6) // carree = 3;
            {
                for (i = 1; i <= 3; i++)
                {
                    for (a = 6; a <= 9; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

            if (x > 3 && x <= 6 && y <= 3)// carree = 4;
            {
                for (i = 3; i <= 6; i++)
                {
                    for (a = 1; a <= 3; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

            if (x > 3 && x <= 6 && y > 3 && y <= 6) // carree = 5;
            {
                for (i = 3; i <= 6; i++)
                {
                    for (a = 3; a <= 6; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

            if (x > 3 && x <= 6 && y > 6) // carree = 6;
            {
                for (i = 3; i <= 6; i++)
                {
                    for (a = 6; a <= 9; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            if (x > 6 && y <= 3) //carree = 7;
            {
                for (i = 6; i <= 9; i++)
                {
                    for (a = 1; a <= 3; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            if (x > 6 && y > 3 && y <= 6) //  carree = 8;
            {
                for (i = 6; i <= 9; i++)
                {
                    for (a = 3; a <= 6; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            if (x > 6 && y > 6) //carree = 9;
            {
                for (i = 6; i <= 9; i++)
                {
                    for (a = 6; a <= 9; a++)
                    {
                        if (tabMask[i, a].Text == unChiffre && tabMask[i, a].Text != "")
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

            return false;

        }


        public bool verifChiffre(string ligne, string colonne, string unChiffre)
        {


            if (verifCol(unChiffre, colonne) == true)
            {
                return true;
            }
            if (verifLigne(unChiffre, ligne) == true)
            {
                return true;
            }
             if (verifCarre(unChiffre, ligne, colonne) == true)
            {
                return true;
            }

           
                return false;
           
        }

        
    }
}

Merci de votre aide