我試圖創建圖像的按鈕,從[設計]視圖在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.
我可以點擊「忽略並繼續」及[設計]視圖中打開罰款,但按鈕不會顯示在該視圖中的圖像(它不顯示它在編譯的程序)。
我在這裏做錯了什麼?
如果我設置圖像屬性在button_click事件單擊時按鈕是不是圖像纔會出現?那不會做這項工作。 – Meredith 2011-02-23 12:02:08
這是正確的,我只是換貨,你可以做到這一點,以確保資源被發現,正確加載。表單設計者和初始化方法有時會導致難以找到的錯誤。 – aL3891 2011-02-23 16:58:55