首页 > 解决方案 > C# 文本框中的文本框数组以构建数独板

问题描述

我想创建一个数独表,我必须在每个包含唯一数字的文本框上添加,在初始文本框的另一侧添加 5 个其他文本框,以便为用户添加一个数字作为草稿。我想知道是否有另一种解决方案可以使用 Windows 窗体来实现?谢谢

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private TextBox textBox1;
        private TextBox textBox2;
        private TextBox textBox3;
        private TextBox textBox4;
        private TextBox textBox5;
        private TextBox textBox6;

        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                {
                    this.textBox1 = new System.Windows.Forms.TextBox();
                    this.textBox2 = new System.Windows.Forms.TextBox();
                    this.textBox3 = new System.Windows.Forms.TextBox();
                    this.textBox4 = new System.Windows.Forms.TextBox();
                    this.textBox5 = new System.Windows.Forms.TextBox();
                    this.textBox6 = new System.Windows.Forms.TextBox();
                    this.SuspendLayout();
                    // 
                    // textBox1
                    // 
                    this.textBox1.Location = new System.Drawing.Point(20 + (i * 39), 85 + (j * 39));
                    this.textBox1.Multiline = true;
                    this.textBox1.Name = "textBox1";
                    this.textBox1.Size = new System.Drawing.Size(106, 94);
                    this.textBox1.TabIndex = 0;
                    this.textBox1.BackColor = Color.Red;

                    this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
                    for (int a = 0; a < 5; a++)
                        for (int b = 0; b < 5; b++)
                        {
                            // 
                            // textBox2
                            // 
                            this.textBox2.Location = new System.Drawing.Point(29, 26);
                            this.textBox2.Name = "textBox2";
                            this.textBox2.Size = new System.Drawing.Size(21, 20);
                            this.textBox2.TabIndex = 1;
                            // 
                            // textBox3
                            // 
                            this.textBox3.Location = new System.Drawing.Point(72, 64);
                            this.textBox3.Name = "textBox3";
                            this.textBox3.Size = new System.Drawing.Size(21, 20);
                            this.textBox3.TabIndex = 2;
                            // 
                            // textBox4
                            // 
                            this.textBox4.Location = new System.Drawing.Point(114, 100);
                            this.textBox4.Name = "textBox4";
                            this.textBox4.Size = new System.Drawing.Size(21, 20);
                            this.textBox4.TabIndex = 3;
                            // 
                            // textBox5
                            // 
                            this.textBox5.Location = new System.Drawing.Point(29, 100);
                            this.textBox5.Name = "textBox5";
                            this.textBox5.Size = new System.Drawing.Size(21, 20);
                            this.textBox5.TabIndex = 4;
                            // 
                            // textBox6
                            // 
                            this.textBox6.Location = new System.Drawing.Point(114, 26);
                            this.textBox6.Name = "textBox6";
                            this.textBox6.Size = new System.Drawing.Size(21, 20);
                            this.textBox6.TabIndex = 5;
                        }
                            // 
                            // Form1
                            // 
                            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                            this.ClientSize = new System.Drawing.Size(800, 450);
                            this.Controls.Add(this.textBox6);
                            this.Controls.Add(this.textBox5);
                            this.Controls.Add(this.textBox4);
                            this.Controls.Add(this.textBox3);
                            this.Controls.Add(this.textBox2);
                            this.Controls.Add(this.textBox1);
                            this.Name = "Form1";
                            this.Text = "Form1";
                        }
                }
        }
    }

我试图创建一个包含总共 81 个框的文本框数组的表单,我想在 81 个文本框的每个角落再添加 5 个文本框,但是这些文本框必须采用 1 到 9 之间的数字 https:// cdn.britannica.com/42/97142-131-E3E24AA5/sudoku-puzzle-games.jpg

谢谢

标签: c#winformssolid-principles

解决方案


推荐阅读