Resources » Code Snippets » Application windows, menus & toolbars

Splash Screen, Login Form and Exit Confirmation with VB.Net


Posted Date: 30-Oct-2010  Last Updated:   Category: Application windows, menus & toolbars    
Author: Member Level: Silver    Points: 50


This sample demonstrate how to make Splash Screen, Login Form and Exit Confirmation with VB.Net (VS 2010).



Introduction



When we use the application, firstly application will run the Splash Screen application. Splash Screen will be active for several second, and then the main of application will show in full screen. Before the user use the application, user must Log in first.

When we exite from the application, application will be confirmation first.

This sample will be use 3 forms:
1. MainForm,
2. SplashForm, and
3. LoginForm.


Create New Project


1. Start VB.Net.
2. Click Menu File -> New -> Project to start a new project.
3. On New Project Dialog Box, choose Windows Application.
4. Enter a name for the project, for example MyApp. Then click Ok button to create the project.

Change The Form Properties


Once the project is created we should see a form named Form1.vb in default setting. Now we will try to change Form1 properties. Click the form in the workspace, or Right-click the form in the workspace and choose Properties to make properties tools active.

The properties tool is use to set various properties object on the project. In this step we will change Name Properties and Text Properties of Form1.vb.

1. Click the Properties Window. Scroll up/down until you find (Nama) property. Set it to MainForm.
2. Scroll up/down until you find Text property. Set it to MyApp. You can see this reflected in the workspace, at the title of form.

Create Splash Form


1. Add new form, type SplashForm as the form name.
2. Change StartPosition property of SplashForm to CenterScreen.
3. Usually Splash Screen hasn't Title form. Change FormBorderStyle to None.
4. From ToolBox, drag-and-drop Label object to SplashForm workspace.
5. Change Text property of Label to This is Splash Screen.
6. Add Timer Object. From ToolBox, drag-and-drop Timer object to SplashForm workspace.
7. Change Interval property of Timer to 1000.

Write this code below at SplashForm code area.

Public Class SplashForm
Private Sub SplashForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'This code make Timer1 automaticly started when SplashForm loading.
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'This code will be close the SplashForm
Me.Close()
End Sub
End Class




Create Login Form


1. Add new form, type FormLogin as the form name.
2. Change the form properties:
2.1. StartPosition to CenterScreen,
2.2. ControlBox to False,
2.3. ShowAtTaskbar to False,
2.4. Text to Log In.
3. Add 2 object Label, 2 object TextBox and 2 object Button to LoginForm.
4. Change objects property:
4.1. Label1 Text to User ID,
4.2. Label2 Text to Password,
4.3. TextBox1 Name to TxtUserId,
4.4. TextBox2 Name to TxtPass,
4.5. TextBox2 PasswordChar to *,
4.6. Button1 Name to BtnOk,
4.7. Button1 Text to Ok,
4.8. Button2 Name to BtnCancel,
4.9. Button2 Text to Cancel.
4. Write this code below at LoginForm code area.

Public Class LoginForm
Public vUserID As String = "admin"
Public vPass As String = "123go"

Private Sub BtnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOk.Click
If TxtUserId.Text = "" Then
MsgBox("You must enter your User ID... ", MsgBoxStyle.Critical, "Error")
TxtUserId.Select()
ElseIf TxtPass.Text = "" Then
MsgBox("You must enter your Password... ", MsgBoxStyle.Critical, "Error")
TxtPass.Select()
ElseIf TxtUserId.Text = vUserID And TxtPass.Text = vPass Then
Me.Close()
Else
MsgBox("User ID or Password invalid. Try again... ", MsgBoxStyle.Critical, "Error")
TxtPass.Select()
End If
End Sub

Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
End
End Sub
End Class



Creating Events at MainForm MyApp


The SplashForm and the LoginForm will be show when the MainForm loading. The MainForm will be active if user can Log In. When we close MyApp, firstly the application will be confirmation it.

Now, back to MainForm. Firstly we will create an event for Form Load. Write this code:

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SplashForm.ShowDialog()
Me.WindowState = FormWindowState.Maximized
LoginForm.ShowDialog()
End Sub


Write this code for Form Close Event:

Private Sub MainForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If MessageBox.Show("Are you sure want to quit? ", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End Sub


Full code for MainForm as show below:

Public Class MainForm

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SplashForm.ShowDialog()
Me.WindowState = FormWindowState.Maximized
LoginForm.ShowDialog()
End Sub

Private Sub MainForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If MessageBox.Show("Are you sure want to quit? ", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End Sub
End Class


That's it.


Did you like this resource? Share it with your friends and show your love!

Responses to "Splash Screen, Login Form and Exit Confirmation with VB.Net"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    vivek
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India