为什么我在添加类时在Designer中出现错误就在Form类的上方 [英] Why I get a error in Designer when I add a class Just above the Form class

查看:128
本文介绍了为什么我在添加类时在Designer中出现错误就在Form类的上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在表单类的上方添加一个类时,我的表单设计器没有加载它显示错误,如下面给出的调用堆栈中



隐藏调用堆栈



在System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)

在System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad( IDesignerSerializationManager manager)

at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)

at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad( IDesignerLoaderHost主持人)





我的代码是这样的:



< pre lang =c#> namespace WindowsFormsApplication1
{
public class myclass
{
int mymember;
}
public partial class Form1:表格
{
public Form1()
{
InitializeComponent();
}
}
}





我在哪里评论myclass我能看到窗口表格设计。当我取消注释时,它在显示设计时再次显示错误。



有人知道为什么会这样吗???



先谢谢。

解决方案

在VS 2013中,当您尝试这样做时会收到错误消息:

< pre lang =text>可以设计类frmInformation,但不是文件中的第一个类。 Visual Studio要求设计人员使用文件中的第一个类。移动类代码,使其成为文件中的第一个类,然后再次尝试加载设计器。

很有可能您也收到此消息。



这是对VS设计师如何运作的限制。在Form1中嵌入你的新类或者在文件的末尾添加它而不是开始(或者更好,将它放在它自己的文件中以便于查找)


问题是因为你在form1类或者你的表单名称之上添加了一些类。要解决此错误,您需要添加要在表单类下面添加的类。


When I added a class just above the form class my form designer not loading it showing error as given below as in call stack

Hide Call Stack

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)


My code is like this :

namespace WindowsFormsApplication1
{
 public class myclass
 {
    int mymember;
 }
 public partial class Form1 : Form
 {
    public Form1()
   {
            InitializeComponent();
    }
 }
}



where ever I comment the myclass I am able to see windows forms design. when I uncomment this it shows error again in showing the design.

Do any one knows why happens like this???

Thanks in Advance.

解决方案

In VS 2013, you get an error message when you try this:

The class frmInformation can be designed, but is not the first class in the file.  Visual Studio requires that designers use the first class in the file.  Move the class code so that it is the first class in the file and try loading the designer again.

There is a good chance that you get this message as well.

It's a restriction on how the VS designer works, is all. Embed your new class within Form1 or add it at the end of the file instead of the start (or better, put it in it's own file so it is easy to find)


The problem is because you add some class above the form1 class or whatever your form name. to resolve this error you need to add classes which you want to add below the form class.


这篇关于为什么我在添加类时在Designer中出现错误就在Form类的上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆