2011-02-23 82 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