PDA

Click to See Complete Forum and Search --> : Is there a way to do this?


quddusaliquddus
Mar 28th, 2010, 04:50 PM
How can I set up a class such that its the main one and so that it is the first to be run by the program?

NickThissen
Mar 28th, 2010, 04:52 PM
Create a method called 'Main' and change the startup object option in the project settings.

If by class you mean a form, then you don't need to create a method called Main, you just need to change the startup object to that form.

quddusaliquddus
Mar 28th, 2010, 05:02 PM
Thanks. Ill try that.

quddusaliquddus
Mar 28th, 2010, 05:07 PM
Hi. Im creating a WPF project and would like to make the Main method or my Main class to run o startup. But I dont get the option in project properties.

NickThissen
Mar 28th, 2010, 05:11 PM
Then you should have posted in the WPF forum instead. I never used WPF so I can't answer your question.

quddusaliquddus
Mar 28th, 2010, 05:13 PM
Sorry. I didnt realise itd make a difference.

jmcilhinney
Mar 28th, 2010, 08:16 PM
Hi. Im creating a WPF project and would like to make the Main method or my Main class to run o startup. But I dont get the option in project properties.

Just as in WinForms, if you want to create your own Main method as the application entry point then you have to disable the Application Framework in the project properties. If you do that then the Startup URI becomes Startup Object and automatically switches from a Window to Sub Main.

That said, in most cases you shouldn't be doing this. This is another case of where you should be explaining what you're actually trying to achieve and not how you're trying to achieve it. Why exactly do you want to do what you're suggesting? Quite possibly you should simply be handling the Startup event of the application.