How do I get Visual Studio 2012 to generate code from a windows form design? - vb.net

I am trying to add a simple windows form to my VB.Net project. I have used the designer to design the form how I want it with buttons, a text box and a Timer. The problem is when I try to view the code, there is only an empty class that looks like this:
Public Class MCastMain
End Class
I have set the application type to a windows form application in the project properties, and I have made a successful build of the application since doing so. I have been scrawling the internet and this forum for about half an hour now and I can't find one other person who is having this problem, nor can I find a tutorial that mentions any special steps that must be taken beyond what I have done. This is the first project I have done in Visual Studio.
I know this is probably stupid simple, but I have no idea what to do. Any help is appreciated as always.

Forms comes as partial class meaning the code is separated in two files.
The "empty" code you shown is from "mcastmain.vb" (if the file is named as the class).
With that one there is a (probably hidden) file "mcastmain.designer.vb" file which contains the generated code by the designer ; and is not meant to be modified (as any designer change will rewrite the file).
To show the hidden files you have to look in the solution explorer on the button on it's top there should be a "show all files" button. (it may be possible to do the same via the menu but I don't have VS right there to be sure where)

Related

Form designer missing controls after installing VS 2017 update

Today, VS 2017 Community Edition recommended I take a small update, which I did.
Now any VB.NET solution that I open shows a blank form (as if adding a new form). However, in examining the files, all of the controls and the associated code are present in the files. It just appears that the VB.NET Form Designer is not happy with something in a file.
Is there anything I can do to kick the Form Designer to display the form correctly or is there anything I can examine to ascertain some specific error it might be throwing so that I can look in the right place for resolution.
I figured it out and thought the solution might be useful for others. For some reason, the new version was converting every VB Form control from this (for example) Me.labelFrequency.Location = New System.Drawing.Point(113, 197) to this Me.labelFrequency.Location = New System.Drawing.Point(-32768, 197)(Note the italicized invalid coordinate). It did this for EVERY control in the project. The negative coordinate was throwing off the Designer (obviously). I cleared the VSTS cache and restored a version of the xyzzy.Designer.VB file with the correct values and it stopped doing this. Left this here in case anyone else found this useful.

What is the difference between the designer.vb page and .vb page?

I am new to framework 3.5. I noticed that when creating a web content form, it creates a aspx.designer.vb page in addition to the aspx.vb page. Can anyone explain the difference to me and the purpose of each?
Can anyone explain the difference to me and the purpose of each?
aspx.designer.vb
Is the designer related autogenerated code by the framework and it contains necessary code for the controls you have placed in your form in designer surface. If you want you can make changes to your controls look and feel using the desinger property window (or) even using this designer file.
aspx.vb is the file where the actual server side code block is present. Like your controls event handler methods etc.
consider going through the MSDN documentation for getting a better understanding on the same.
I have noticed it too..
I think the .vb file has the code you have written.. and the designer.vb file has options on how to display your code in the screen..
You can open the files with Visual Studio or NotePad++ or just Notepad to see the difference..

In a VB project, is it possible to have a resx file with the same name than a form?

Good Morning,
I'm working in a VB project (usually I work mostly on C#) and there is an issue at the compilation that I don't understand:
In my VB project I have a Windows Form (with its own Designer.vb and .resx) and a Resources file (with its Designer.vb), both have the same name, and it seems that it produce the following compilation error:
Error 13 The item "obj\Debug[projectName].[fileName].resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
I can't change the name of one of them as it's an internal design pattern (and it works in C# projects).
Doesn't VB accept such pattern ? If yes, are there any workaround possible ?
Or do I have something wrong in one of my project files ?
Regards
Edit: As my problem may not be very clear, here is the pattern I have to respect in this project :
This doesn't compile. In VB only as I'm using this pattern in C# projects without any issues.
You probably have a duplicated entry inside the form.designer. I ran across this problem once
Goto to your Solution Explorer, Select your project and click on the show all files icon at the top of the Solution Explorer. You should then be able to expand out your form.vb to see all the sub files. Look for a frmMain.Designer.vb and check it for a duplicate resource entry. If that doesn't work try cleaning your Solution
Extracted from here, check the link it may help:
VB.net designer error
Edit: I would delete the form. Save the code behind and create it with another name pasting the code.
Finally I found where the problem was:
It was an issue with namespaces, as VB generated in VisualStudio doesn't provide any namespace by default in WinForms, ones I gave a namespace to the form and the designer of the form, and gave a different namespace to the second resx (via it's properties/Custom Tool Namespace) it compile.

Why would a .sln file open as empty in VB2010Express when it should open referring to projects etc. as it did before?

Why would a .sln solution file open and appear empty in Microsoft Visual Basic 2010 Express - i.e. no windows showing projects and code files etc.
When I inspect the file in a text editor, it contains references to vbproj files (which are present) which indicate that it should not appear as empty.
No error messages are reported when the file is opened.
Update:
(To illustrate my problem)
It attempts to load the projects that belong to the solution:
And then results in a bare solution screen
Express Edition is limited to on project per solution. If you have more than that, you will not be able to use the solution file with the express edition of visual studio. You will need to open the projects separately.
The answer is that the projects did load for the solution but the Window to display them was not open or visible. To make it visible, go to the View menu and select Other Windows:
This displays the 4 projects referenced by the solution
Forgive me for blurring the project names but this might be commercially sensitive and therefore not for public awareness. But you get the picture.
In summary it was my lack of knowledge about the tool, though I had looked under the Window option first thinking along these lines, but the View menu is actually where one would go to display things about the project.
Thanks to everyone for your contributions.

Clicking and draggging a user control in VB .NET creates object reference error message

Failed to create component 'User Control 1'. the error message follows:
'System.NullReferenceException : Object reference not set to an instance of an object.
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object Component, Object Value)
.............. etc..........
What should I do to fix this error?
When a User Control won't load into the Visual Studio designer here is what you need to do. These instruction are for vb.net project but c# should be similar. Also, before doing this close all open windows (or at least the source and designer files of the control you are working on.)
One last thing. The FIRST thing you should do is ensure that restarting visual studio doesn't fix the problem. If not you can try the steps that follow. These instructions assume that the errant user controls are in control library project in visual studio. If not you should be able to adjust the directions a bit to get it to work but it is much easier when the control is in its own project.
Do the following:
Make the control library your startup project.
Open the properties for the control library project and click on the debug tab.
Under Start Action click the Start external program option and browse to the Visual Studio executable.
NOTE: what this means is that when you run your solution it will fire up another instance of Visual Studio instead of actually running your solution. The First Instance of Visual Studion (INSTANCE_1) will "host" a second instance of visual studio (INSTANCE_2) when you run it.
Run your solution. INSTANCE_2 will load.
Switch back to INSTANCE_1.
In INSTANCE_1 hit CTRL-ALT-E. This will open up the exceptions dialog box. Check On the THROWN column checkbox next to Common Language Runtime Exceptions.
NOTE: This will ensure that INSTANCE_1 will BREAK at ANY runtime error even if it is hit in a try block.
Switch to INSTANCE_2. In Solution Explorer double-click to open the errant user control.
You should find that INSTANCE_1 OF Visual Studio should have stopped at the line of code that caused the designer to not load the control. Fix the code (which usually means testing for IsNot Nothing before references an object properties...but could mean other things.)
Also, sometimes I find that the control WILL load in INSTANCE_2 instead of breaking on an error in INSTANCE_1. In that case just stop debugging...close INSTANCE_2. Save/Restart INSTANCE_1 and your problem will often have gone away.
The lesson is this. User Control MUST be able to load/reference all objects and their members in order to load it into the designer. So for User Controls that will be placed onto other containers I will usually design events to notify the parent rather than trying to push objects into the child control.
Hope this helps for future reference on this old question.
Seth
Instead of the error occurring when you open up a form for editing, it sounds like this is occurring when you are already editing a form and adding new user controls. A CodeProject article that was previously mentioned shows what to do in the case of a form not loading correctly, rather than a specific user control.
Does your user control have any properties that map to custom objects (i.e. not Integer or String)? If so, the Form Designer will attempt to load your properties into the Property Editor. If showing the properties generates an error, the Form Designer will show that to you. I think this is what is happening with your user control.
If you could edit the question and add more information about the nature of the error (more of the error text), it would assist others in helping you better. Alternatively, see if you can find the property that might be causing the error (e.g. whether any property relies on a non-null value being set). You can also take a look at this MSDN article for tips on how to limit the control for just run-time.
Thanks, Seth, for this post! Your solution helped me nail down the error. The only thing I would add to this is that when "INSTANCE_2" loads, you may need to actually load the project file in INSTANCE_2. I needed to because I wasn't dealing with a control library, but instead had custom User Controls defined in the same project that the forms were located in. Once I loaded the project in INSTANCE_2, I opened the erring form and that caused INSTANCE_1 to pop up to the line of offending code in the User Control.
I have found that this error often occurs when control dlls are not building properly. 95% of the time this is remedied by simply restarting Visual Studio.