VS2012 VB.NET Designer Errors - vb.net

I was commenting out code in my project and starting getting errors in the designer which stopped me from viewing the page.
After this i decided to put everything back so I was able to run the program again. (Yes, i have made sure to comment everything back)
I am now getting designer errors on some of my pages. Here is the errors and examples.
Here is the list of errors I am getting:
http://i.stack.imgur.com/NFX8G.png
The application does run but if i click on the frmMediaDevices1.vb page this is the errors that then appears:
http://i.stack.imgur.com/XZrPE.png
I think it maybe something to do with the Windows.Media.Player that i have referenced in the project on frmMain.vb as when I click the errors the designer code appears highlighting my media player on the page.
Does anyone know how I can maybe refresh the designer? Or know how i can fix this issue?

Form's class must be the first in the form's class module.
Problem you described happens if you have files like
Form1.designer.vb
Form1.vb
Form1.resx
and into file Form1.vb which contains Class Form1 you add class Class Helper1. You can do it, but class Form1 must be kept as the first class (tompost in code) in Form1.vb.
Of course, this also includes the case if you have only one (proper) class in the file (Class Form1), but you comment it out.
Just be careful with your commenting and you will avoid that error.

Related

How can I recover program.vb{Design] pane after renaming Form1?

My vb.net program was functioning properly. After I renamed Form1 in the code pane of Visual Studio 2015 the Program.vb[Design] pane will not open and the following message appears:
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.
The name change was in the first class (form) so I cannot move it further up.
Before the change there were no errors. After the change there are many handles clause, variable not declared and not a member of errors.
I had 2 choices for Startup form in the Application tab of My Project before the change. After I have only 1 choice from a dropdown list. Both choices were Class names.
Is there anything I can do to recover the Designer view? Should I just recreate the form?
Thanks in advance, for any suggestions.

The class MyApplication can be designed, but is not the first class in the file [duplicate]

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?
That's because you added some class or other code above the class definition in form1.vb. Remove that.
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).
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.

Undefined UserControl error

I just created a UserControl in my application, the problem I have is that every time I edit the code of UserControl I have to delete the UserControls already added to the GUI because it fails to compile.
The project / application is called Panel and UserControl called TimerPanel, which contains a couple of text boxes within a GroupBox.
The error reads
Type 'Panel.TimerPanel' is not defined.
The strange thing is that everything works OK until I edit the UserControl.
Like I said, if I delete the UserControl GUI, compiled and then added again to the GUI control, everything works OK.
I read somewhere on this forum that you must add a reference to System.Windows.Forms, and I did and it behaves the same.
What can I be doing wrong?
When you get that error go and build the project again, see if that fixes the issue (building a project again fixes lots of errors and when you add/change a user control is needed to use it)

How to create nested user controls in VB.net?

I have the following classes in my vb.net application:
Form1
Usercontrol1
LnkLabel
Usercontrol1 is a user control , and doesnt contain any extra code. LnkLabel is a class that inherits Forms.Label. Its code is goven below:
Public class LnkLabel
Inherits Label
Sub clk handles me.click
Process.start(text)
End sub
End class
When I add an Instance of LnkLabel to usercontrol1, i get an error "type LnkLabel is not defined"
There are three instances of the error in uc1.designer.vb.How can I solve these Errors?
Note:
Visual Studio 2010
.Net FW 3.5
Edit:
The usercontrol1 donot contain any code that might be causing the error. It is just a new usercontrol added to the project.
LnkLabel is added to UC1 by the designer, not by using code at runtime.
The class name is LnkLabel, and not "LinkLabel".
I find that the easiest way to resolve this type of issue is to open the Designer.vb file directly.
To do this, choose Show All Files from the Project menu, then expand UserControl2. Double-click on the UserControl2.Designer.vb file.
You should also be able to get there by double-clicking on the error in the compile errors list.
Once there, search for the definition of UserControl1 or uc1, whatever it may be called (ensure you are in the type definition area, not the property assignment area).
Looking at the definition may give you an instant clue as to the problem (is it in the wrong namespace; did the name of the user control change after you created it, but the change was not propagated to this form; etc).
If it is not obvious what the issue is, use VS intellisense to help you get the right class. I usually clear the previous type definition and start typing the name I know it should be (i.e. UserControl), then select the appropriate value from Intellisense.
Selecting a different class (or correcting the class selection) will require a change to the control instatiation code and may also require a change to some of the properties (I usually just remove the properties I am unsure of and update the control directly in the designer).
Before you switch back to the designer, ensure that you save your changes and, if possible, compile the app.

VB.NET - Ctrl + Break suspends code on "Partial Class frmMain"

This is an IDE question for Visual Basic 2008 Express Edition. It might be a bug in the IDE, or maybe it's my fault somehow?
My main form is named frmMain and in my application's properties I have set frmMain as my startup object. All of that seems like what a lot of software engineers do.
But while debugging I hit Ctrl + Break, as I have done for years, and I get an behavior in the IDE that I wasn't expecting. Upon doing so, I get the green background text and the green arrow indicating in a tooltip:
This is the next statement to execute when this thread returns from the current function.
Even if I didn't have the designer document open, it automatically opens frmMain.Designer.vb in the editor and hihglights line in green. The line is of course: Partial Class frmMain which is line 2 of the file. (Yes, it's highlighting the second line of the designer-generated code.)
frmMain seems to have fully loaded and it's my startup object. As far as I know, there shouldn't be a "next statement to execute" at all because code should be idle. I don't want to see the Designer.vb document... I want to edit my own code.
What's causing this? Even though my form is behaving just fine, could there somehow be an unfinished aspect of loading the form such that it is "not returning" from a function?
The Visual Basic compiler will add an entry point in your form. The entry point is the standard main function or "shared sub main", which in turn contains the code "application.run(new form)". Since this is compiler generated code there is no source location, so the Visual Basic editor highlights the class definition.
The clue to this is in the call stack. Notice the Main().
Shared Sub Main()
Application.Run(new frmMain)
End Sub
I found the answer on my own:
I checked the "Enable application framework" checkbox in the solution's properties, and all is well!
I believe this issue arose when I was working on experimental code in which I had desired to make Sub Main my startup object. I had cleared the checkbox because doing so is necessary to use Sub Main.
When the experiment didn't pan out I reset the startup object back to frmMain, and my app worked fine. However I had not re-checked the box. I hadn't noticed the change in the IDE behavior for several days (when I needed the more standard behavior) so I had not observed any correlation.
Although checking that box is definitely the solution, it's still not exactly clear to me is what the heck this box actually does, other than cause me to spend a lot of time on StackOverflow.com! ;-)
To others who encounter a similar situation, I'm now quite confident that my settings were not corrupt, and if you're using the Express edition, please don't be mislead by MS documentation which may lead you to believe it's the "Just My Code" option. This option cannot be changed in the Express versions. (But it's not because you can't turn it on -- It's because you can't turn it OFF in Express!)
Thanks to everyone for your efforts.
I'm going to guess that it is trying to show you the equivalent of:
Application.Run(new frmMain)
This is the code that gets generated to startup your form. But in VB.NET this code gets burried. Create a Main() function and change your startup type to that with this line in it and repeat the process. You'll see it highlight Application.Run. That is the method that contains your Windows message pump loop.