在一个Winform程序中新建一个Resource File,生成Resource1.resx和Resource1.Designer.cs文件,之后在Resource1.Designer.cs文件中添加一个方法:
- C# code
public static string GetString(string name){ return ResourceManager.GetString(name);}
然后在Form1.Designer.cs中:
- C# code
this.Text = Resource1.GetString("String1");
之后双击Form1.cs,窗口显示异常:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
Method 'WindowsApplication1.Resource1.GetString' not found.
Hide
at Microsoft.VisualStudio.Shell.Design.VirtualType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
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)
但是运行程序,程序运行正常,且Resource1中的String1也能成功显示。
望高手指点!~~
------解决方案--------------------
不要修改****.Designer.cs,这个文件有visual studio维护