Scott
Scott

Reputation: 6251

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

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.vb file 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:

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.

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?

Upvotes: 12

Views: 31439

Answers (4)

Steven Hintzsche
Steven Hintzsche

Reputation: 1

Had a student that renamed the public class at the top of his code and got this error. We changed it back to form1 and then all the errors went away.

Upvotes: 0

Ganesh S
Ganesh S

Reputation: 431

You added another class in your form and that is the reason of the error. I had ran into same issue. I had added another class in the form and that caused this error. To resolve, I moved the new class to a module(created new module) and then access the class in the required form.

Upvotes: 0

Yaakov
Yaakov

Reputation: 11

What worked for me is editing both Form1.vb and Form1.Designer.vb and placing at the beginning of both files: Namespace Whatever and 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).

Upvotes: 1

Fede
Fede

Reputation: 44038

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

Upvotes: 42

Related Questions