Form code is empty but the project compiles and th

2019-09-08 18:32发布

I have a project that has only one form, that is Form1.vb.

When I double click this file to edit the controls with the toolbox, the file is opened, but it is empty.

The strange thing is that when I compile and run the project, the GUI that I had created in this file (Form1.vb) is shown like it whas there, but as I said, the file is empty, so I can't edit the GUI.

How can I fix it?

A screenshot of the problem: A screenshot of the problem

For if you need, a screenshot of the project folder: A screenshot of the project folder

3条回答
三岁会撩人
2楼-- · 2019-09-08 18:36

This is what I would do first: Click on "My Project" in Solution Explorer and check out under Application what your Startup form and Application type is.

查看更多
干净又极端
3楼-- · 2019-09-08 18:41

Solved.

I can't get the code of Form1.vb, but I created a new form and copy the code of Form1.Designer.vb (this file was in my folder, and due to it the GUI was shown when I compile & run the project) to the form designer file of the new form. To did it, I opened the file with a text editor.

It allowed me to edit the existing GUI preserving the properties of the controlls that I had created.

查看更多
爷的心禁止访问
4楼-- · 2019-09-08 18:51

Your code file might be empty but the .Designer.vb file is not (from the screenshot it's seen that it's 15 KB).

The problem here is that your project seem to have lost the "link" between the designer file and the code file, and treats Form1 as a normal class.

If you don't have a backup of your code file you will not be able to get your code back, but you can still make your form editable again by following these steps:

  1. (This step is very important) Go into your project folder and copy Form1.vb, Form1.Designer.vb and Form1.resx to another folder.

  2. Now that you have a copy of the files, go a head and delete Form1 from Visual Studio, and delete any left-over Form1 files from your project directory.

  3. In Visual Studio right-click your project and go to Add > Existing file.... Browse to the folder where you copied the Form1 files in step 1, and select all three.

  4. Press "Open", and the form should now be imported to your project as an editable form again.


EDIT:

Try opening the Form1.vb in Notepad and write:

Public Class Form1

End Class

in it, then redo the steps above.

查看更多
登录 后发表回答