[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Setting the primary form in C#

Hi,

Anybody know how to quickly change the primary form for the project?

Thnks,
Bob
0
ba272
Asked:
ba272
  • 4
  • 4
2 Solutions
 
cyberdevil67Commented:
Hi ba272,

  Yeah in the project menu -> project properties you cna tell it from there which form to use. However it must have the intialization section for it to work.

Cheers!
0
 
YurichCommented:
in project menu you can set a project as a start-up project for your solution and only if your project is selected.
i couldn't fine any property in project properties to specify which form is a primary one.

what makes your form is primary (or main form, or starting form) is the presence of main in it... following the logic, copy-paste your Main function into the cs file of your to-be-primary form and comment it out where it was before:

[STAThread]
static void Main()
{
      Application.Run(new Login());
}

Login is the name of your primary-to-be  form

regards
0
 
cyberdevil67Commented:
Actually thats not true you can change any form with the right credentials as I said, to be the main form to load, but as yurich has pointed out it must have the main, it must have intialization etc for it to work.

I have projects here that when I design a new form I add this info and change the form to run at startup, and it runs the new form.

But again as I said it must have the right credentials to be able to run.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
YurichCommented:
aha, found it in the properties page...

well, the thing is, if you do it cyberdevil's way, you'll have to implement Main as I said,

If you do it my way, you don't have to specify anythin in the properties

any will do

regards
0
 
cyberdevil67Commented:
Actually you still have to set it in properties, if you have more than obe form with the main option, the compiler is not smart enough to know whuch one it is you wish to run. I know I do it all the time.
0
 
YurichCommented:
comment out the main in the one you're not using as a main one?
0
 
cyberdevil67Commented:
You don't need to comment it out, just select the form in the properties and tell it which form to use as the startup form. Told you I do it all the time
0
 
YurichCommented:
of course you don't have to but if you do, you don't have to select anything in the properties...
0
 
ba272Author Commented:
Yurich,

I ended up doing it your way.  It's code that's generated automatically, so when it came for me to replace the initial form with a new one, I was at a loss.

Thanks for the help guys.

Bob
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now