简体   繁体   中英

Unable to Set Startup Form in Visual Studio 2012 (VB.NET)

Okay, in Visual Studio 2012 I have a VB.NET project with originally two forms. Form1 was originally set as the startup form and then obsoleted. Form2 is a nearly identical form that has all of the new desirable functionality.

In my project's settings, Form2 doesn't appear as an available option for Startup Form. (Though it is a normally-created form that inherits Form) After some "troubleshooting," Form1 has been deleted, resulting in the the "Enable Application Framework" option being disabled and no Startup Object being available. When I select anything from the Startup Object drop-down, either Sub Main or Form2, I have an error message stating either "Sub Main not found in Solution" or "Form2 is a type in Solution and cannot be used as an expression" respectively. If I try to enable "Enable Application Framework," I receive an error popup stating "Startup object must be a form when 'Enable application framework' is checked." And Application.Designer.vb is empty.

Some things I've tried:

  • Clean and Rebuild Solution
  • Restarting Visual Studio
  • Temporarily deleting Form1 (it's still excluded from project)
  • Added a new form, per Neolisk's advice. It appeared in the available objects. I selected it and turned on application framework. From here, I copied the initialization code from Form2's designer code into Form3's. All was alright. Then, I copied Form2's main code into Form3. Now, "Form3 is a type in Solution and cannot be used as an expression" appears in my error list.

With that said, my question is how can I get Visual Studio to recognize my form as a form and set Form2 as the startup object?

Found it! The issue was an overload of the form's constructor taking a form as a parameter. Since this was the only constructor in the file, I guess it caused confusion. Commented that out and all was right with the world again.

在form2的new()函数中添加InitializeComponent()

Sometimes you have a different class name from the form file name.

Check if the class name is listed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM