Help with startup form.....

G

Guest

I'm using VB.Net 2005 beta 2 and have my login form (login.vb) specified as
the startup form. If the user is successful logging in, I call my main form
(main.vb). This all works fine but the problem is that the login form stays
open. I put a me.close (in the login form) after opening the main form but
that seems to close everything and the main form is not displayed.

I thought I could call a Sub Main() that calls the login form, closes it
then calls the main form. However, I don't see where I can call the sub Main
since the project property only gives you an option to call a Startup Form.

Thanks!
 
K

Ken Tucker [MVP]

Hi,

I tested this with VS.Net 2005 RC but I believe it will work with
beta 2. First add a module with a public sub main. Second open myproject in
the solution explorer and uncheck enable application framework. You now
should be able to set the startup object to sub main.

Ken
 
K

Ken Tucker [MVP]

Hi,

Forgot to mention. VB.Net has some new events if you enable the
application framework. There will be a button in my project that says view
application events. If you press the button it will add
applicationevents.vb. You can add code to the application startup event
which shows the login form. If the user is not authorized to use the app
you can cancel the startup.

Namespace My

' The following events are availble for MyApplication:
'
' Startup: Raised when the application starts, before the startup form
is created.
' Shutdown: Raised after all application forms are closed. This event
is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled
exception.
' StartupNextInstance: Raised when launching a single-instance
application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is
connected or disconnected.
Partial Friend Class MyApplication

Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As
Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs)
Handles Me.NetworkAvailabilityChanged
' event raised when you connect or disconnect from a network
MessageBox.Show(e.IsNetworkAvailable.ToString)
End Sub

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles
Me.Startup
Dim dr As DialogResult = LoginForm1.ShowDialog
' In my app the loginform returns ok if the user is authorized
e.Cancel = dr <> DialogResult.OK
End Sub
End Class

End Namespace


Ken
 
G

Guest

Thanks Ken. When I uncheck "Enable Application Framework" I can then select
the Sub Main as the startup. However, I loose access to ensuring that I only
have one instance of my application started and the splash screen. This
seems pretty straightforward....any ideas why its not?????

Thanks!
 
K

Ken Tucker [MVP]

Hi,

The application framework take care of that for you. You are
probably better off using the application startup event instead of sub main
if you need the features of the application framework.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top