|
-
Jul 4th, 2007, 04:03 AM
#1
Thread Starter
Addicted Member
Doubt about Main() method
I'm new at VB.Net, and I haven't had too much time to work on it, so I'm still trying to learn several things.
In VB6, when using the Main sub there was no problem with doing:
Load frmMain
frmMain.Show
However, using the Show() method in .Net causes the form to appear and disappear, and I have to use ShowDialog() instead. Am I doing it correctly?
-
Jul 4th, 2007, 04:22 AM
#2
Re: Doubt about Main() method
Yes .ShowDialog will put the form on top of the other forms.
"The dark side clouds everything. Impossible to see the future is."
-
Jul 4th, 2007, 05:47 AM
#3
Thread Starter
Addicted Member
Re: Doubt about Main() method
Just in case I haven't been too clear, when I said the form appears and disappears using Show() I meant that once the forms appears the program is finished afterwards.
 Originally Posted by Asgorath
Yes .ShowDialog will put the form on top of the other forms.
Yes, I've seen it's the method to show a form as modal as well.
Thanks for your reply.
-
Jul 4th, 2007, 06:06 AM
#4
Re: Doubt about Main() method
It disappears because the only thing to keep an application running is a message loop. To start one of those you need to use Application.Run.
VB.NET Code:
Public Class MyApp
<STAThread()> Public Shared Sub Main(args As String())
Application.EnableVisualStyles()
Application.Run(New frmMain())
End Sub
End Class
ShowDialog should not be used unless it really is a dialogue box.
-
Jul 4th, 2007, 06:06 AM
#5
Re: Doubt about Main() method
You could put FrmMain as starting form...
"The dark side clouds everything. Impossible to see the future is."
-
Jul 4th, 2007, 06:38 AM
#6
Thread Starter
Addicted Member
Re: Doubt about Main() method
 Originally Posted by penagate
Application.Run(New frmMain())
I see, thanks for pointing out that.
This made me wonder another thing, should I use Application.Exit() instead of Me.Close() when closing the main form in this situation? Also, I guess Application.Exit() dispose every other form in memory, and I shouldn't worry about iterating through all of them? or should I? and, would there be any difference between a MDI application and SDI with multiple forms?
-
Jul 4th, 2007, 06:40 AM
#7
Re: Doubt about Main() method
Application.Exit will, yes, close every form. If your application tends to spawn windows all over the place and you want to say goodbye to the whole lot at once, this is a quick way to do it. If you have one window open, calling its Close method will end the application too. If this window is an MDI form, all of its child windows will be closed, so it is equivalent to calling Application.Exit. However, with an MDI application, I would use Close (not that I can think of any particular reason why.)
-
Jul 4th, 2007, 06:56 AM
#8
Thread Starter
Addicted Member
Re: Doubt about Main() method
 Originally Posted by penagate
Application.Exit will, yes, close every form. If your application tends to spawn windows all over the place and you want to say goodbye to the whole lot at once, this is a quick way to do it. If you have one window open, calling its Close method will end the application too. If this window is an MDI form, all of its child windows will be closed, so it is equivalent to calling Application.Exit. However, with an MDI application, I would use Close (not that I can think of any particular reason why.)
But is Application.Exit() anything like End? or does it successfully release every form? I'm very used to iterate through any active form and unload and release it, so I guess I'll keep doing it, but if I can sometimes save that time of writing code the better.
-
Jul 4th, 2007, 07:28 AM
#9
Re: Doubt about Main() method
 Originally Posted by Neverbirth
iterate through any active form and unload and release it
That's exactly what Application.Exit does.
 Originally Posted by [url=http://msdn2.microsoft.com/en-us/library/ms157894.aspx]Application.Exit Method (System.Windows.Forms)[/url]
The Exit method stops all running message loops on all threads and closes all windows of the application. This method does not necessarily force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return.
-
Jul 5th, 2007, 08:28 AM
#10
Re: Doubt about Main() method
 Originally Posted by Asgorath
You could put FrmMain as starting form...
Or, if you're using VS 2005, you could enable the Application Framework and use the Application Events, like StartUp, Shutdown, and UnhandledException to better manage your WinForms app. But why should you want to do things the easy way?
-
Jul 6th, 2007, 03:16 AM
#11
Thread Starter
Addicted Member
Re: Doubt about Main() method
 Originally Posted by bgmacaw
Or, if you're using VS 2005, you could enable the Application Framework and use the Application Events, like StartUp, Shutdown, and UnhandledException to better manage your WinForms app. But why should you want to do things the easy way?
I didn't know about it, I read your post yesterday, and found the Application Events to be interesting.
Thanks.
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
|