2009-07-25 28 views
2

當我嘗試單擊設計選項卡上,以獲得設計圖,我得到這個錯誤:無法看到在Visual Studio中的設計視圖2008年C#Windows窗體由於奇怪的錯誤

To prevent possible data loss before loading the designer, the following errors must be resolved:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: Form1 --- The base class 'System.Windows.Forms.Form' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

我我喜歡進入設計師,不知道什麼是錯的。我的Form1代碼看起來像這樣在頂部:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Drawing.Drawing2D; 
using System.Diagnostics; 

    namespace foobar 
    { 
     public partial class Form1 : Form 
     { 

     List<CharLabel> allChars = new List<CharLabel>(); 

     public Form1() 
     { 
... etc ... 

任何想法?

回答

2

當您直接從代碼編輯器更改部分類(如Forms)中的名稱空間或其他項目時,您正在發出瘋狂邀請。顧名思義,部分類是在代碼視圖中「部分」定義的類,但是另一部分由VS自動生成,並且是類的另一部分。在該部分中,它包含所有UI元素,字體,默認值等的定義。當您在類的一部分中更改名稱空間時,另一部分不知道該做什麼,然後開始出現有趣的錯誤。當更改名稱空間,類名稱和事件方法名稱時,始終使用VS中的重構選項。

在你的情況,我可能會回到老字號它有,然後使用重構選項VS提供(高亮顯示組件名稱,Ricgh點擊,refactor->重命名)

希望這有助於。

2

你是否檢查過消息中的推薦內容?也就是說,你是否證實System.Windows.Forms.dll在你的項目中被引用?

要添加引用如果缺少執行以下操作

  • 點擊:瀏覽 - >解決方案資源管理器
  • 右鍵單擊References節點,選擇「添加和借鑑」
  • 轉到淨標籤
  • 滾動,直到看到System.Windows.Forms.dll的
  • 選擇並點擊OK
+0

我沒有(和錯誤沒有提及「.dll」部分,所以我不知道看看)。我將如何提供這種參考? 關於這一點的事情是,它只是突然開始給出錯誤,然後重新啓動可能會修復它一點,等等。 感謝您的幫助。 – cksubs 2009-07-25 01:29:47

+1

@cksubs,我只是添加了一些步驟,以將其添加到您的項目中。 – JaredPar 2009-07-25 01:35:38

0

我也經歷過這個,我通過糾正引用庫缺失來解決它。

你可以檢查你的錯誤列表。

相關問題