我尝试使用以下方法在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.我可以单击忽略并继续",并且[设计]视图打开很好,但是该按钮没有在该视图上显示图像(它确实在编译的程序中显示了该图像).我在做什么错了?解决方案您不应直接编辑Form.Designer.cs,因为它会被设计者覆盖.当您打开设计器时,设计器实际上在Form.designer.cs文件中运行代码.由于该代码实际上是由vs2010运行的,因此其环境略有不同只是一个测试,请尝试通过button_click事件方法设置image属性,这可能是由于某种原因找不到图像I am trying to create a button with image and no text from the [Design] view on Visual Studio 2010. I drag & dropped the button, then I click the Image Property, I select a png image from my resource file, but the property always remain empty and the button doesn't have image neither on the [Design] view or in the compiled program.I tried setting the image on the Form.Designer.cs file with: // // 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;And when I go to the [Design] View, I get the error :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.I can click "ignore and continue" and the [Design] view opens fine, but the button doesn't show the image on that view (it does show it in the compiled program).What am I doing wrong here? 解决方案 you should not edit the Form.Designer.cs directly because it will be overwritten by the designer. the designer actually runs the code in the Form.designer.cs file when you open the designer. since that code is actually run by vs2010, its environment is a little diffrentjust a test, try setting the image property from the button_click event method instead, it might be that the image is not found for some reason 这篇关于Visual Studio 2010上的图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-12 15:03