|
-
August 8th, 2005, 04:57 PM
#1
Form Disappear Automatically
This is very strange, I have a form, a very simple "Hello World" type of form. If I just do F5, the form shows up, no problem. Now I added a module, with the following code:
***********************
Module MainModule
Dim frm1 As New frmLogin1()
Sub Main()
If PrevInstance() Then
msg = "This Program is already running. Please shut down the currently running"
msg = msg & " process before starting a new one"
MsgBox(msg, vbInformation)
Exit Sub
Else
Startapplication()
End If
End Sub
Function PrevInstance() As Boolean
If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
Return True
Else
Return False
End If
End Function
Sub Startapplication()
frm1.Show()
End Sub
End Module
**********************************
And I changed the startup object to "sub main" in the project property.
Now, when I do F5, the frmLogin shows, and then disappear automatically...
Can anybody tell me what I did wrong? many thanks...
Last edited by MacArthur; August 8th, 2005 at 04:59 PM.
-
August 8th, 2005, 08:39 PM
#2
Re: Form Disappear Automatically
If you use a Main method then the application exits when the Main method completes. If you call Show on a form, as soon as the form is displayed the method returns. This means that the Main method then completes and your app exits, hence the form closes. That is why you call Application.Run with an instance of your form class rather than Show, e.g.:
Code:
Application.Run(frm1)
Application.Run does not return until the form it was passed is closed.
-
August 8th, 2005, 09:35 PM
#3
Re: Form Disappear Automatically
-
August 9th, 2005, 07:16 AM
#4
Re: Form Disappear Automatically
that or showdialog instead
Nicolas Bohemier
-
August 9th, 2005, 09:11 AM
#5
Re: Form Disappear Automatically
ShowDialog is for showing a dialogue. Application.Run is for running an application. While ShowDialog may appear to do the same thing it is more correct to call Application.Run in this case.
-
August 9th, 2005, 09:45 AM
#6
Re: Form Disappear Automatically
The point here is to stop the thread both do it. But in any case, do application.run..
Nicolas Bohemier
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|