1

単純な数独アプリケーションを作成しました。各3x3の正方形はユーザーコントロールであり、このスケルトンコードCellBlock.Designer.csが含まれ、自動生成されたコードが含まれていますCellBlock.cs

namespace Sudoku
{
    partial class CellBlock
    {

        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }


        private void InitializeComponent()
        {
            this.CellOne = new System.Windows.Forms.MaskedTextBox();
            this.CellFour = new System.Windows.Forms.MaskedTextBox();
            this.CellFive = new System.Windows.Forms.MaskedTextBox();
            this.CellSix = new System.Windows.Forms.MaskedTextBox();
            this.CellTwo = new System.Windows.Forms.MaskedTextBox();
            this.CellThree = new System.Windows.Forms.MaskedTextBox();
            this.CellSeven = new System.Windows.Forms.MaskedTextBox();
            this.CellEight = new System.Windows.Forms.MaskedTextBox();
            this.CellNine = new System.Windows.Forms.MaskedTextBox();
            this.SuspendLayout();
            // 
            // CellOne
            // 
            this.CellOne.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.CellOne.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.CellOne.Location = new System.Drawing.Point(8, 8);
            this.CellOne.Mask = "0";
            this.CellOne.Name = "CellOne";
            this.CellOne.PromptChar = ' ';
            this.CellOne.Size = new System.Drawing.Size(26, 26);
            this.CellOne.TabIndex = 0;
            this.CellOne.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

            //CellTwo through CellNine omitted for brevity

        // 
        // CellBlock
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        this.Controls.Add(this.CellNine);
        this.Controls.Add(this.CellEight);
        this.Controls.Add(this.CellSeven);
        this.Controls.Add(this.CellThree);
        this.Controls.Add(this.CellTwo);
        this.Controls.Add(this.CellSix);
        this.Controls.Add(this.CellFive);
        this.Controls.Add(this.CellFour);
        this.Controls.Add(this.CellOne);
        this.Name = "CellBlock";
        this.Size = new System.Drawing.Size(107, 107);
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    private System.Windows.Forms.MaskedTextBox CellOne;
    private System.Windows.Forms.MaskedTextBox CellFour;
    private System.Windows.Forms.MaskedTextBox CellFive;
    private System.Windows.Forms.MaskedTextBox CellSix;
    private System.Windows.Forms.MaskedTextBox CellTwo;
    private System.Windows.Forms.MaskedTextBox CellThree;
    private System.Windows.Forms.MaskedTextBox CellSeven;
    private System.Windows.Forms.MaskedTextBox CellEight;
    private System.Windows.Forms.MaskedTextBox CellNine;
}

}

Sudoku.csこれらのファイルは、メインファイルと同じソリューションにあります。プロジェクトメニューからソリューションにユーザーコントロールを追加しただけです。Sudoku.Designer.csこれは、 VisualStudioによって自動的に生成されたのコードです。

namespace Sudoku
{
    partial class Sudoku
    {

        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Sudoku));
            this.cellBlock1 = new Sudoku.CellBlock();
            this.cellBlock2 = new Sudoku.CellBlock();
            this.cellBlock3 = new Sudoku.CellBlock();
            this.cellBlock4 = new Sudoku.CellBlock();
            this.cellBlock5 = new Sudoku.CellBlock();
            this.cellBlock6 = new Sudoku.CellBlock();
            this.cellBlock7 = new Sudoku.CellBlock();
            this.cellBlock8 = new Sudoku.CellBlock();
            this.cellBlock9 = new Sudoku.CellBlock(); //errors occur at these lines

}


        private CellBlock cellBlock1;
        private CellBlock cellBlock2;
        private CellBlock cellBlock3;
        private CellBlock cellBlock4;
        private CellBlock cellBlock5;
        private CellBlock cellBlock6;
        private CellBlock cellBlock7;
        private CellBlock cellBlock8;
        private CellBlock cellBlock9;

    }
}

簡潔にするために自動生成されたコードの一部を省略していますが、それはすべて正しいと思います。ソリューションをビルドすると、次のような9つのエラーが発生します。タイプ名「CellBlock」がタイプ「Sudoku.Sudoku」に存在しません。

次の行を参照しますthis.cellBlock1 = new Sudoku.CellBlock();。など。「参照の追加」への参照を追加する必要があると思いましたが、CellBlock, even though it's within the same solution, but when I clickプロジェクトの下に何もリストされていません。

4

2 に答える 2

2

名前空間の名前を新しいもの以外に変更してからSudoku、ソリューションをクリーンアップして再構築します。

現在のコントロールを削除 CellBlock して、再度追加します。

于 2012-06-22T17:35:02.733 に答える
1

あなたのクラスSudokuがあなたの名前空間と同じであるSudokuため、コンパイラは class 内で呼び出されるCellBlock内部クラスが必要であると考えているためだと思いますSudoku。ac# ランタイムとコンパイラが手元にないので、試して再現することはできません。

名前空間またはクラス名のいずれかをリファクタリングして、独自の識別子を持つようにしてください。

于 2012-06-22T17:21:05.940 に答える