vb.net 类 Form1 可以设计,但不是文件中的第一个类[...]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13519751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:27:37  来源:igfitidea点击:

The class Form1 can be designed, but is not the first class in the file[...]

vb.netvisual-studio-2010

提问by Scott

I'm a newbie on vb.net, and I was in progress with my first application... and found some example code in the msdn so I just replaced my Form1.vbfile content with the content from the MSDN. When I roll back the changes, and tried to compile my old code then hundreds of errors appeared, and when I switch to the Form1[Design]tab I see this:

我是 vb.net 的新手,我正在进行我的第一个应用程序......并在 msdn 中找到了一些示例代码,所以我只是用Form1.vbMSDN 中的内容替换了我的文件内容。当我回滚更改并尝试编译我的旧代码时,出现了数百个错误,当我切换到Form1[Design]选项卡时,我看到:

The class Form1 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.

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

I'm really new on vb.net and the visual studio itself, and I dont know what to do in this case, is my work destroyed or what?

我对 vb.net 和视觉工作室本身真的很陌生,我不知道在这种情况下该怎么办,我的工作被破坏了还是什么?

回答by Federico Berasategui

That's because you added some class or other code above the class definition in form1.vb. Remove that.

那是因为您在 form1.vb 中的类定义之上添加了一些类或其他代码。去掉那个。

回答by Yaakov

What worked for me is editing both Form1.vb and Form1.Designer.vb and placing at the beginning of both files: Namespace Whateverand at the end of both files: End Namespace. The "Whatever" can be any name not already used in the program (or the name of an existing Namespace that you're already using).

对我有用的是编辑 Form1.vb 和 Form1.Designer.vb 并将它们放在两个文件的开头:Namespace Whatever和两个文件的末尾:End Namespace. “随便”可以是程序中尚未使用的任何名称(或您已经在使用的现有命名空间的名称)。