Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?:-\

  • *Experts*
Posted

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)

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...