*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 You have to show the form before you run the Application. Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 It worked! I have another question. Does Application.Run(); only work in Main? anywhere else I put it the program just immediately shut down. Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 Yes; Main is the only sub that executes on its own (on the starting of the app). The only way to get any other subs to run is to call them (directly or indirectly) through the Sub Main (In C#... in VB.NET, you don't even need an Application.Run statement for the program to start). Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 I tried removing Application.Run here but the program immediately closed. static void Main() { Form3 frm3=new Form3(); frm3.Show(); Application.Run(); } Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 Is that sub in the same form that is set as your startup object? Right click on the project in the solution explorer and click Properties. There will be a "Startup Object" setting. Make sure it is set to the same form that the Sub Main is located in. Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 I went to Set startup projects and they are both under WindowsApplication2 namespace. Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 Yes, but there should be two selections available: "WindowsApplication2.Form1" and "WindowsApplication2.Form2" If Sub Main is in Form1, you want the startup object to be the first one, otherwise you want it to be the second one. Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 You mean this picture (attatched) Quote C#
*Gurus* divil Posted February 1, 2003 *Gurus* Posted February 1, 2003 No, you're looking at the solution properties. You want the project properties. Right-click on your project node, not the solution node, and click properties. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 I found it and changed the starting object to form1 (it was my only choice.) but it still does the same thing when I remove Run. Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 Oh, when you remove the Run command? You need the Run command in the Sub Main of your startup object; sorry, I misread your original statement. If you take out the Run statement, then your program is never really executing; it's simply starting the program, and closing it immediately because there's nothing to do. When you use the Run command, it starts a standard Windows message loop for the window, meaning that the window becomes active, and recieves events and various window messages that are sent to it. Without a message loop and a thread to run it on, there is no program. Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 (In C#... in VB.NET, you don't even need an Application.Run statement for the program to start). I tried removing that and also just writing Run(); but it never works without Application.Run(); Is that the way it should be? Also, I noticed in the properties window something about having more than one Main(). Is that possible? Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 I meant that in C# you do need it, but in VB.NET you don't. Yes, Application.Run(); is correct. Sorry for being unclear. Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 Ok. That clears things up alot. Thanks so much for all your help. I am learning things. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.