|
-
Sep 27th, 2003, 02:49 PM
#1
Thread Starter
New Member
Replacement for VB6, Load(form_name)?
Hello,
This feels like a stupid question that I'm asking, but regardless it's been a giant thorn in my side...so...
In the process of converting a Vb6 app to VB.Net (not using the wizard, since it's a bit too complicated for the wizard), I ran into the problem of replacing VB6's method for loading and showing a form:
Set variable_for_form = New form_name_here
Load variable_for_form
Now, with VB.Net, the clearest method I can think of as a replacement is as follows:
Dim variable_for_form = New form_name_here
variable_for_form.Show()
-----
Before I go on, I must add that the app is set to start by using a module called "modmain.vb", that holds basically all of the procedures that get used multiple times in the application. Modmain.vb has the procedure "Sub Main()", which is where the application looks to first when it is run. Thus, my code for showing my first form (form_name_here in the code above), is in Sub Main() in modmain.vb.
The code is literally as follows:
Sub Main()
Dim fForm = New frmSplash
fForm.Show()
End Sub
With frmSplash being the first form my app needs to display.
Continuing...if I use "variable_for_form.Show()", the application will start, and promptly quit. The form does load, because I can see it doing such, but as soon as it is displayed it will close and the application will close with it.
If I use "variable_for_form.ShowDialog()", the form displays just fine, with the exception that any code in the "Form_Load()" procedure for that particular form, is not run. And, it kind of needs to be...
Basically my main question is:
"How to I load and display a regular, basic, no frills, plain 'ol form in a VB.Net Windows Application?"
-----
Undoubtedly there is the simplest of solutions to this problem, and I'm terribly sorry for having wasted your time. If that's the case...just smack me over the back of the head and give me the right code so I'll be on my way, thanks.
Your replies are much appreciated,
Daniel Gow.
-
Sep 27th, 2003, 03:09 PM
#2
Sleep mode
Did you try this and gave you same puzzle ?
VB Code:
Public Sub Main()
Dim frm As New Form
Application.Run(frm)
End Sub
-
Sep 27th, 2003, 03:26 PM
#3
Thread Starter
New Member
Thanks for your swift reply...
Application.Run() did the trick admirably. I wasn't familiar with that procedure, and it all works well now.
Thanks much again,
Daniel Gow.
-
Sep 27th, 2003, 06:37 PM
#4
PowerPoster
Some more information...
the Show() method with show the form, and immediately return and continue code execution. So what is happening is your form is shown, but since code execution keeps going, it is closed because when the end of Sub Main is reached, the whole application closes.
If you want to stop execution when showing a form, you use the ShowDialog() method. It will halt execution until that form is closed.
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
|