2011-02-23 99 views
1

我試圖創建圖像的按鈕,從[設計]視圖在Visual Studio 2010中沒有文字我拖累&下降的按鈕,然後我點擊圖像屬性,我選擇PNG圖像從我的資源文件,但屬性始終保持空,並且該按鈕在[設計]視圖或編譯的程序中都沒有圖像。圖像按鈕2010

我嘗試設置在Form.Designer.cs圖像與文件:

// 
    // button1 
    // 
    this.button1.Location = new System.Drawing.Point(73, 11); 
    this.button1.Name = "button1"; 
    this.button1.Size = new System.Drawing.Size(39, 34); 
    this.button1.TabIndex = 10; 
    this.button1.UseVisualStyleBackColor = true; 
    this.button1.Image = Properties.Resources.close_project_img; 

當我去到[設計]視圖中,我得到的錯誤:

To prevent possible data loss before loading the designer, the following errors must be resolved: 

Projectitem unavailable.  

Instances of this error (1) 

1. Show Call Stack 

at EnvDTE.ProjectItem.get_FileCount() 
at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObjectProvider.GetFileNameForProjectItem(ProjectItem item) 
at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObject.BuildType() 
at Microsoft.VisualStudio.Design.Serialization.ResXGlobalObject.GetObjectType() 
at Microsoft.VisualStudio.Shell.Design.GlobalType.get_ObjectType() 
at Microsoft.VisualStudio.Shell.Design.GlobalObject.GetHashCode() 
at System.Collections.Generic.ObjectEqualityComparer`1.GetHashCode(T obj) 
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key) 
at Microsoft.VisualStudio.Shell.Design.GlobalObjectService.GetGlobalObjects(Type baseType) 
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetTypeFromGlobalObjects(String name, Boolean throwOnError, Boolean ignoreCase) 
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase) 
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name) 
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.GetRuntimeType(String typeName) 
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.GetType(String typeName) 
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.GetType(String typeName) 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyReferenceExpression(IDesignerSerializationManager manager, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError) 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError) 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement) 
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement) 

Help with this error 

Could not find an associated help topic for this error. 

我可以點擊「忽略並繼續」及[設計]視圖中打開罰款,但按鈕不會顯示在該視圖中的圖像(它不顯示它在編譯的程序)。

我在這裏做錯了什麼?

回答

1

你不應該直接編輯Form.Designer.cs因爲它會由設計師來覆蓋。當您打開設計器時,設計者實際上在Form.designer.cs文件中運行代碼。因爲代碼實際上是由VS2010運行,它的環境是有點不同勢

只是一個測試,嘗試從button_click事件方法設置圖像屬性,而不是,它可能是圖像沒有發現因某些原因

+0

如果我設置圖像屬性在button_click事件單擊時按鈕是不是圖像纔會出現?那不會做這項工作。 – Meredith 2011-02-23 12:02:08

+1

這是正確的,我只是換貨,你可以做到這一點,以確保資源被發現,正確加載。表單設計者和初始化方法有時會導致難以找到的錯誤。 – aL3891 2011-02-23 16:58:55

0

我關閉了項目,取消了resources.resx和resource.designer.cs,重建的資源文件,現在工作得很好,不知道是什麼問題。

+0

有時,Forms Designer會自己卡住,重置會修復它。其他時候,您可能需要違反L3891的建議並自行編輯設計器文件以使其不被卡住。從VCS獲取日誌可幫助您查看更改的內容是否有助於調試這些問題。 – 2011-02-24 03:22:59

+0

只需關閉該項目並打開它爲我工作。我一直在試圖找出至少20分鐘的錯誤,現在我感到很蠢 – Connell 2011-10-21 09:47:17