private void textChangedEventHandler(object sender, TextChangedEventArgs args)
        {
            MyTextBox myTextBox = (MyTextBox)sender;

            int valueText = 0;

            bool success;

            switch (currenType)
            {
            case "9x9":
                for (int i = 0; i < myTextBox.Text.Length; i++)
                {
                    if (myTextBox.Text[i] < '1' || myTextBox.Text[i] > '9')
                    {
                        myTextBox.Text = myTextBox.PastText;
                        return;
                    }
                }
                ///////////////



                if (myTextBox.Text != "")
                {
                    valueText = Convert.ToInt32(myTextBox.Text);
                }


                success = Interface.ChangeNumber(sudoku, new Number.Position(myTextBox.row, myTextBox.column), valueText);

                UpdateRightness();
                break;

            case "16x16":
                for (int i = 0; i < myTextBox.Text.Length; i++)
                {
                    if (myTextBox.Text[i] < '1' || myTextBox.Text[i] > '9')
                    {
                        myTextBox.Text = myTextBox.PastText;
                        return;
                    }
                }
                ///////////////


                if (myTextBox.Text != "")
                {
                    valueText = Convert.ToInt32(myTextBox.Text);
                }


                success = sudoku.ChangeNumber(new Number.Position(myTextBox.row, myTextBox.column), valueText);

                UpdateRightness();
                break;
            }
        }
        private MyTextBox TextBox_9_9Add(int row, int column)
        {
            MyTextBox tb = new MyTextBox();

            tb.row             = row; tb.column = column;
            tb.Name            = "_" + Convert.ToString(row) + "_" + Convert.ToString(column);
            tb.TextAlignment   = TextAlignment.Center;
            tb.FontSize        = 45;
            tb.Background      = new SolidColorBrush(Colors.Transparent);
            tb.BorderBrush     = new SolidColorBrush(Colors.Black);
            tb.BorderThickness = new Thickness(2);

            if ((column + 1) % 3 == 0)
            {
                tb.Margin = new Thickness(0, 0, 10, 0);
            }
            else if ((row + 1) % 3 == 0)
            {
                tb.Margin = new Thickness(0, 0, 0, 10);
            }
            if ((column + 1) % 3 == 0 && ((row + 1) % 3 == 0))
            {
                tb.Margin = new Thickness(0, 0, 10, 10);
            }

            tb.Text         = "";
            tb.TextChanged += textChangedEventHandler;
            tb.LostFocus   += lostFocus;
            sudokuGrid.Children.Add(tb);

            Grid.SetColumn(tb, column);
            Grid.SetRow(tb, row);

            tb.Text = Interface.GetNumber(sudoku, new Number.Position(row, column)).Value.ToString();


            ///Console.WriteLine(sudoku.ReturnNumberByPosition(new Number.Position(column, row)).Value);

            return(tb);
        }
        private void lostFocus(object sender, RoutedEventArgs e)
        {
            MyTextBox myTextBox = (MyTextBox)sender;

            if (myTextBox.Text != "")
            {
                bool IsAdmissibleValue = true;
                foreach (int number in AdmissibleValues)
                {
                    if (Convert.ToInt32(myTextBox.Text) != number)
                    {
                        IsAdmissibleValue = false;
                    }
                    else
                    {
                        IsAdmissibleValue = true;
                        break;
                    }
                }
                if (!IsAdmissibleValue)
                {
                    MessageBox.Show("Введено недопустимое число", "Внимание", MessageBoxButton.OK);
                    myTextBox.Text = myTextBox.PastText;
                    return;
                }
            }

            myTextBox.PastText = myTextBox.Text;
            /////////////////////////////////////////


            UpdateRightness();

            LousySudoku.Debug.ShowSudoku(sudoku, 9);
            LousySudoku.Debug.ShowSudokuRightness(sudoku, 9);
        }
Ejemplo n.º 4
0
        private MyTextBox TextBox_9_9Add(int row, int column)
        {
            MyTextBox tb = new MyTextBox();
            tb.row = row; tb.column = column;
            tb.Name = "_" + Convert.ToString(row) + "_" + Convert.ToString(column);
            tb.TextAlignment = TextAlignment.Center;
            tb.FontSize = 45;
            tb.Background = new SolidColorBrush(Colors.Transparent);
            tb.BorderBrush = new SolidColorBrush(Colors.Black);
            tb.BorderThickness = new Thickness(2);

            if ((column + 1) % 3 == 0)
            {
                tb.Margin = new Thickness(0, 0, 10, 0);
            }
            else if ((row + 1) % 3 == 0)
                tb.Margin = new Thickness(0, 0, 0, 10);
            if ((column + 1) % 3 == 0 && ((row + 1) % 3 == 0))
                tb.Margin = new Thickness(0, 0, 10, 10);

            tb.Text = "";
            tb.TextChanged += textChangedEventHandler;
            tb.LostFocus += lostFocus;
            sudokuGrid.Children.Add(tb);

            Grid.SetColumn(tb, column);
            Grid.SetRow(tb, row);

            tb.Text = Interface.GetNumber(sudoku, new Number.Position(row, column)).Value.ToString();

            ///Console.WriteLine(sudoku.ReturnNumberByPosition(new Number.Position(column, row)).Value);

            return tb;
        }