示例#1
0
        private void DrawSudoku(GenerateSudoku sudoku)
        {
            ContextMenu menu = new ContextMenu();
            menu.Background = Brushes.White;
            for (int i = 0; i <= 9; i++)
            {
                MenuItem item = new MenuItem();
                item.Header = i.ToString();
                menu.Items.Add(item);
                item.Click += item_Click;
            }

            for (int i = 0; i < sudoku.n * sudoku.n; i++)
            {
                for (int j = 0; j < sudoku.n * sudoku.n; j++)
                {
                    TextBox txtBox = new TextBox();
                    txtBox.Name = "n" + i.ToString() + j.ToString();
                    txtBox.Height = 30;
                    txtBox.Width = 30;
                    txtBox.FontSize = 16;
                    txtBox.Foreground = Brushes.Black;
                    txtBox.FontWeight = FontWeights.Bold;
                    txtBox.BorderThickness = new Thickness(1.0);
                    txtBox.TextAlignment = TextAlignment.Center;
                    txtBox.Text = sudoku.removed_arr[i, j].ToString();
                    Grid.SetColumn(txtBox, i);
                    Grid.SetRow(txtBox, j);
                    grdSudoku.Children.Add(txtBox);
                    txtBox.IsReadOnly = true;
                    txtBox.SelectionBrush = Brushes.White;
                    txtBox.BorderBrush = Brushes.White;

                    if (txtBox.Text == "0")
                    {
                        txtBox.Clear();
                        txtBox.ContextMenu = menu;
                        txtBox.ContextMenuClosing += tb_ContextMenuClosing;
                        txtBox.SelectionBrush = Brushes.Green;
                    }
                }
            }
        }
示例#2
0
        private void NewGame()
        {
            int level;
            if (rdbEasy.IsChecked == true)
            level = 1;
            if(rdbMedium.IsChecked == true)
            level = 2;
            if (rdbHard.IsChecked == true)
            level = 3;
            else
                level = 1;

            sudoku = new GenerateSudoku(level);
            DrawSudoku(sudoku);
        }