C#的VS中打开Form1.cs出错:类 Form1 可以进行设计,但不是文件中的第一个类。拿到一个VS2010的项目,C#代码。
用VS打开后,双击Form1.cs去打开,结果出错:
若要在加载设计器前避免可能发生的数据丢失,必须纠正以下错误类 Form1 可以进行设计,但不是文件中的第一个类。Visual Studio 要求设计器使用文件中的第一个类。移动类代码使之成为文件中的第一个类,然后尝试重新加载设计器。
此错误的实例(1)
1。
隐藏调用堆栈
在 System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
在 System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.
DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
有关此错误的帮助
MSDN 帮助
有关此错误的论坛文章
在 MSDN 论坛中搜索与此错误相关的文章
如图:
【解决过程】
1.参考:
类可以进行设计,但不是文件中的第一个类去移动代码,使得form1为第一个类:
变成:
?1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
......
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1(string sss)
{
InitializeComponent();
//this.textBox1.Text = sss;
}
public Form1()
{
InitializeComponent();
Class1 C = new Class1();
C.visit(textBox2);
}
......
}
public class a
{
public void s()
{
......
}
}
}
然后再去双击Form1.cs,看看效果。
2.貌似是可以了,
但是又出现其他错误:
设计器无法处理第 101 行的代码: for (int i = 0; i < s.FrameCount; i++) { s.GetFrame(i); } 方法“InitializeComponent”内的代码由设计器生成,不应手动修改。请移除任何更改,然后尝试重新打开设计器。此错误的实例(1)
1。
WindowsFormsApplication3 Form1.Designer.cs 行:101 列:1
显示调用堆栈
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.CreateQuoteExpression(XmlElementData xmlElement)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.XmlElementData.get_CodeDomElement()
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.EndElement(String prefix, String name, String urn)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.Parse(XmlReader reader)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.ParseXml(String xmlStream, CodeStatementCollection statementCollection, String fileName, String methodName)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e)
在 System.CodeDom.CodeMemberMethod.get_Statements()
在 System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
在 System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
在 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
在 System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
有关此错误的帮助
未能找到与此错误相关的帮助主题。 检查 Windows 窗体设计时错误列表
有关此错误的论坛文章
在 MSDN 论坛中搜索与此错误相关的文章
然后点击到对应代码去看看:
也看不太懂。
注释掉算了:
?1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private void InitializeComponent()
{
//StackTrace a1111 = GetStackTrace(Thread.CurrentThread);
//System.Diagnostics.StackTrace s = new System.Diagnostics.StackTrace();
//for (int i = 0; i < s.FrameCount; i++)
//{
// s.GetFrame(i);
//}
//a a = new a();
//a.s();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
......
看看效果,最后终于可以打开窗口设计器了:
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。