Пример #1
0
        private void MostrarCasillas()
        {
            TextBox auxb;
            int     numero = 0;

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    auxb   = (TextBox)tableroSudoku.GetControlFromPosition(j, i);
                    numero = tablero.BuscarCasilla(i, j).Valor;
                    if (numero == 0)
                    {
                        auxb.ResetText();
                    }
                    else
                    {
                        auxb.Text = Math.Abs(numero).ToString();
                    }
                }
            }
        }
Пример #2
0
        private void Cargarbutton_MouseUp(object sender, MouseEventArgs e)
        {
            InfoLabel.ResetText();


            this.Cursor = Cursors.AppStarting;
            CambiarFondoBoton(sender, e);
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @Directory.GetCurrentDirectory().ToString() + "\\Tableros";
            openFileDialog1.Filter           = "All files (*.*)|*.*|xml (*.xml)|*.xml";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;
            TextBox auxb;

            Elementos.TableroSudoku tableroAux = tablero;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            InfoLabel.Text = "Cargando tablero.";
                            tablero        = new Elementos.TableroSudoku();
                            tablero.CargarTablero(myStream);
                            myStream.Close();
                            InfoLabel.Text = "Comprobando...";
                            WaitSeconds(0.2);
                            tablero.ResolverTablero();
                            if (tablero.TableroLleno() != true && tablero.ComprobarTablero() != true)
                            {
                                MessageBox.Show("El tablero cargado no se pudo resolver. Seleccione otro tablero.");
                            }
                            else
                            {
                                InfoLabel.Text = "Tablero cargado.";
                            }


                            tablero.LimpiarTablero();
                            LimpiarTablero();
                            for (int i = 0; i < 9; i++)
                            {
                                for (int j = 0; j < 9; j++)
                                {
                                    auxb = (TextBox)tableroSudoku.GetControlFromPosition(j, i);
                                    if (tablero.BuscarCasilla(i, j).Estatico == true)
                                    {
                                        auxb.ReadOnly = true;
                                    }
                                }
                            }
                            MostrarCasillas();
                            MostrarFondos();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

            this.Cursor = Cursors.Default;
        }