2012-06-22 189 views
1

我在CellBlock.Designer.cs創建了一個簡單的數獨應用,其中每個3×3的正方形是用戶控制,與此骨架代碼,而且全部自動生成的代碼中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中的代碼,再次由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; 

    } 
} 

我認爲這都是正確的,儘管爲了簡潔起見,我省略了一些自動生成的代碼。當我構建解決方案,我得到這樣的錯誤9: 類型名稱「監獄分區」不在類型「Sudoku.Sudoku」

引用該讀線存在:我想,也許我this.cellBlock1 = new Sudoku.CellBlock();等。需要添加對CellBlock, even though it's within the same solution, but when I click添加引用的引用,項目下沒有任何內容。

+0

什麼行數導致錯誤? – user12345613

+0

@讀取'this.cellBlock1 = new Sudoku.CellBlock();'的行(見我的編輯)。 –

+0

嘗試'this.cellBlock1 = new CellBlock();' – Damith

回答

2

將您的名稱空間重命名爲Sudoku以外的新名稱,然後清理解決方案並重建它。

刪除當前的CellBlock控件並再次添加它們。

+0

清理固定的解決方案。感謝您的幫助。 –

1

我認爲這可能是因爲你的類Sudoku與你的命名空間Sudoku相同,所以編譯器認爲在類Sudoku中應該有一個名爲CellBlock的內部類。我沒有,沒有一個C#運行時和編譯器方便,所以我不能嘗試和重現。

嘗試重新命名命名空間或類名,使其具有自己的標識符。

+0

我重新考慮類名爲'SudokuWindow',這也重新考慮了行'this.cellBlock1 =新的數獨。 CellBlock();'this.cellBlock1 = new SudokuWindow.CellBlock();',它仍然失敗。 –

+0

@pythonscript正確,因爲'SudokuWindow'是一個沒有'CellBlock'的類...你需要重構,所以命名空間和類是不同的,所以生成的代碼會說...'new namespace.CellBlock()' - 在未來的情況下,我會保持包名的唯一性,以避免這些情況。 – user12345613

+0

對,這就是我的想法。我不願意手動更改這些行(我需要這樣做,因爲重新分解類*不會更新這些行),而且我不想手動更改designer.cs文件。當我重新分班時,它會改變有問題的線路,這仍然不正確。如果我重新命名命名空間,它不會更改這些行(因此不會修復問題),除非手動更改它們。 –

相關問題