/ / Nie można znaleźć niestandardowej kontroli użytkownika w rozwiązaniu? - c #, winforms

Nie można znaleźć niestandardowej kontroli użytkownika w rozwiązaniu? - c #, winformy

Stworzyłem prostą aplikację Sudoku, w której każdy kwadrat 3x3 stanowi kontrolę użytkownika, z tym kodem szkieletu CellBlock.Designer.cs i tylko automatycznie wygenerowany kod 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;
}

}

Te pliki są w tym samym rozwiązaniu co Sudoku.cs, główny plik. Po prostu dodałem kontrolę użytkownika do rozwiązania za pośrednictwem menu projektu. To jest kod w Sudoku.Designer.cspo raz kolejny automatycznie generowane przez Visual Studio.

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;

}
}

Myślę, że wszystko jest w porządku, mimo że jestempomijając niektóre automatycznie generowane kody ze względu na zwięzłość. Gdy buduję rozwiązanie, pojawia się 9 takich błędów: Nazwa typu „CellBlock” nie istnieje w typie „Sudoku.Sudoku”

odniesienie do linii, które czytają: this.cellBlock1 = new Sudoku.CellBlock();itp. Pomyślałem, że może muszę dodać odniesienie do CellBlock, even though it"s within the same solution, but when I clickDodaj odniesienie`, nic nie jest wymienione w projekcie.

Odpowiedzi:

2 dla odpowiedzi № 1

zmień nazwę swojego obszaru nazw na nowy inny niż Sudoku a następnie wyczyść rozwiązanie i odbuduj je.

usuń prąd CellBlock kontrolki i dodaj je ponownie.


1 dla odpowiedzi nr 2

Myślę, że może tak być, ponieważ twoja klasa Sudoku jest taki sam jak twoja przestrzeń nazw Sudoku więc kompilator uważa, że ​​powinna istnieć klasa wewnętrzna o nazwie CellBlock wewnątrz klasy Sudoku. Nie mam pod ręką środowiska uruchomieniowego i kompilatora c #, więc nie mogę spróbować odtworzyć.

Spróbuj przefaktoryzować przestrzeń nazw lub nazwę klasy, aby miała swój własny identyfikator.