mjsnow Posted September 27, 2003 Posted September 27, 2003 I am sure there is a very simple answer but I am mystified. I have a class that at startup creates an instance of a form. The problem is the form just flashes on the screen and the program normally terminates without any errors. Here is the code (theForm is just a generic form added from the Solutions Explorer): Public Class Class1 Private Sub showIt() Dim aForm As New theForm() aForm.Show() End Sub Public Shared Sub main() Dim AClass As New Class1() AClass.showIt() End Sub End Class What do I need to do to keep the form open and ready for business and not have the program terminate?:-\ Quote
*Experts* mutant Posted September 27, 2003 *Experts* Posted September 27, 2003 The problem is that you are starting the message loop for your form so it exits. To start a message loop for your app using the form do this: Application.Run(New theForm) Quote
mjsnow Posted September 30, 2003 Author Posted September 30, 2003 Thanks, that did the trick. Here is an example class just in case anyone else needs to understand how it works. It can be modified to do some sort of logic choice and open the correct form. In this example, it just opens one of the forms but it could be modified to use a select statement in the main method to open a form. Imports System.Windows.Forms Public Class Class1 Private Sub showIt() Application.Run(New theForm()) End Sub Private Sub showItAlso() Application.Run(New theFormToo()) End Sub Public Shared Sub main() Dim theClass As New Class1() theClass.showIt() End Sub End Class Quote
*Experts* mutant Posted September 30, 2003 *Experts* Posted September 30, 2003 Sorry, I forgot one word in my last, I meant to say "...you are not starting..." but I see you got the idea. :) Quote
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.