How can I recreate a designer.vb file? - vb.net

I have a windows forms application in which one of the designer.vb files is missing and has apparently been missing for years (checked all my backups). When I right-click on the vb file in Solution Explorer and select "View Designer", nothing happens. The Windows form designer generated code is still in the vb file, and the form shows up fine when the application runs. Is there any way to recreate the designer file so I can edit the form?

Create a new Form and copy the code from the InitializeComponent method of the old form into the same method in the ".designer.vb" file of the new Form (and replace the existing code in this method.). Also copy the designer generated variable declarations.
Since InitializeComponent creates all the controls and sets all the form properties, this copies the whole design of the old form to the new form.
You will have to copy your own code (containing Load and Click methods and so on) from the old ".vb" file into the new ".vb" file as well.

Related

How to find a form from many forms in vb6 on a existing project

I am working on a old project of vb6 which has hundreds if forms. I am able to run the application and have to fix a runtime error in a form which pop up. I don't know the name of the form and only have visual reference. I tried using debug but It has continues SQL statements running in a loop. Any advice is appreciated.
Thanks.
Search the code for the form caption, or the labels of controls on the form, using visual studio's "find in files" or simlar function of your favourite editor.
If the caption is set in the form design, this will take you to the .frm file the form is stored in. You can open this in Notepad or another editor to get the name of the class (which is usually the same as the filename).
If the caption is set in code, you can place a breakpoint on that line. Again, this will lead you to the code which instantiates the form.

Form code is empty but the project compiles and the GUI is shown

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:
For if you need, a screenshot of the project folder:
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:
(This step is very important) Go into your project folder and copy Form1.vb, Form1.Designer.vb and Form1.resx to another folder.
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.
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.
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.
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.
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.

main.vb, main.designer.vb and missing Form Designer

I have been working with "visual basic.net" on a "windows forms" application. While manipulating controls and adding event handlers I noticed the resultant code was being generated within a file named 'main.designer.vb'. However, if I look in the solution explorer for my project there is no 'main.designer.vb' file, just 'main.vb'.
This is not a colossal problem as it runs properly. However, having closed the 'form designer' window I now cannot reopen it! 'main.vb' has no option to 'view in form designer'.
Any advice on this?
Would it be possible to copy the contents of 'main.designer.vb' in to 'main.vb' and delete 'main.designer.vb' entirely? If I did this, the next time I manipulated the form would the code be added to 'main.vb' or would a new 'main.designer.vb' be created?
I seem to have sorted out the problem.
'main.vb' was completely empty. All the code I had generated and written directly was inside 'main.designer.vb'. However, once I made a class definition within 'main.vb':
Public Class main
End Class
and then cut/pasted all my custom event handler code and subroutines from 'main.designer.vb' to THAT class - all was well. 'main.vb' now shows the correct form icon and FINALLY offers the correct 'view designer' context menu option.
I am not sure why it happened in the first place though.
Look in the Solution Explorer in Visual Studio. In the toolbar in this window is a button called "Show all files". Click it.
Then every file in the projects folder is actually shown in the solution explorer. Expand the treenodes for the form and you will see the designer.vb.
There are also buttons for switching between code-view and designer view. Just remember to select the form in the solution explorer for the buttons to show the correct form in the designer.

Corrupt forms, not displaying in "startup form"?

In properites>Application>"Startup form" combobox, in my VS VB.NET project, I see only 2 forms listed, while my application has 6 forms. Does this mean something is corrupt?
I tried to make a new project, then copy only the old vb files into this new project. But still only those two (of 6) forms show up in the "Startup form" combo box.
Well, that's pretty odd. This list is almost certainly filled from the project file, the <SubType> element should be significant. But you eliminated that possibility by recreating the project file from scratch. I can't see how a property on a form would make it disappear from the list.
One thing you could try is editing the My Project\Application.myapp file with Notepad. Copy the solution first and make sure it isn't loaded in VS. Change the <MainForm> element to one of the forms that isn't listed. Load the project and see what is shown in the project property page and if anything breaks when you compile it.

Clean up Designer.vb file in Visual Studio 2008

I noticed that my Designer.vb file of one of my forms has a lot of controls that aren't even used or visible on my form. This is probably from copying controls from my other forms. Is there a way to clean up the Designer.vb file and get rid of all the unused controls?
**UPDATE: This is for a Windows Form project.
The only real solution I see is to copy all the controls into a new form by selecting them in the designer. This way all the not created controls should not follow you to the next form.