Hi,
I was wondering if there is a way to immediately hide the startup form on startup. The Me.visible = False and Me.hide() Methods don't work.
I am trying to make a simple program that has a login form and the main form. When my program starts i want the login screen to appear and the main form to immediately disappear, then when the user clicks OK the login screen closes and the main form shows. Everything works except when the program runs both the login and the main form window appear and i can't seem to make the main form disappear, and for other reasons setting the login form as the startup form is not an option.
Hope this is a simple fix.
Connor

hiding the startup form
David Tatton
If
Form1.Visible = False ThenForm1.Visible =
TrueForm1.BringToFront()
End Ifslyi
There are a couple of ways:
1. Use a sub Main(). You can control which forms show at what point.
2. Set the opacity to zero, so even though the form is 'shown' it is effectively invisible.
3. You can have a look at this post I placed some time ago and see if it helps http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=900622&SiteID=1
gafferuk
You are right, it is complicated. You don't need it to show in the system try, you can eliminate that portion of it.
If you want to use Sub Main() - which, based on your reply I would recommend - simply set a Sub Main() function as your startup for the project (add a sub Main() function in a module).
Module Module1
Sub Main()
Dim login As New Form1
Dim loginResults As DialogResult = login.ShowDialog
If loginResults = DialogResult.OK Then
'validate credentials
' if CredentialsOK then show MainForm
Application.Run(Form2)
End If
End Sub
End Module
Perhaps a better, more asthetic way, would to actually show your main form, then show a login dialog on top of the form. This, at least, shows the user what application they are supplying credentials for. In this virus/spyware-laden world, it's a polite thing to do. You don't need to populate anything on the form initially, or just show everything disabled until valid credentials have been supplied.
Al42
Hi,
If you have VB 2005 in the project properties is a section called "Windows application framework properties" there is a combobox title "Shutdown mode" with two options in it:
1. When startup form closes
2. When last from closes
If you choose the option number two there you can start your project with the login form and when the user logins show the main form and close the login form.
Good luck.
RaphaelGray
Alexandre Martins
1. If you want to use sub main() I had neglected to mention that you need to go to you application properties and disable 'use application framework': the sub main function will show up in the list of startup objects.
2. Frank Carr is correct - you can do what you want in the MyApplication_startup event: this may be a better place, however I've never used that event to pre-show another form before. You'll have to try it. To 'cancel' loading the application (failed login, for example) the arguments passed have a 'cancel' property: set it true.
beto81
Peter McEvoy
I read through your post and i was kinda confused by it and was wondering if there is any other way because it seems i little complicated for what i want to do. All i want to do is make it so the login form appears first then once the OK button is clicked instead of calling the main form and telling it to open (because I've been having trouble with that) it tells it the show. Or if thats not possible then maybe you could post a simple code example about the Sub.Main() method. Also i would prefer if i didn't show up in the system tray.
edsela
1. From Solution Explorer, select "My Project" to bring up the project properties and select the Application tab there (it's the default). Check "Enable Application Framework" and click on the "View Application Events" button to bring up the code window for application events.
2. In this code window, you'll see a Partial Class called "Partial Friend Class MyApplication" in the "My" Namespace. You'll want to add a routine to called MyApplication_Startup that's defined like so in VB.Net:
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
3. In this routine you'll want to add code that show your login dialog form. If the login is successful, exit the routine and your main start-up form will be shown. If the login fails, exit the application.
Note that Application Events can also be used to handle the application shutdown and unmanaged exceptions.
R.Tutus
Thanks,
i just wanted to hide the form when loading then be able to redisplay it from the systray
your app sub did the trick.