About, Splash, and Login Forms


The TransparencyKey and Opacity properties enable you to build forms with unusual and interesting shapes. Although these would be distracting if used for the bulk of a business application, they can add a little interest to About dialog boxes, splash screens, and login forms.

These three kinds of forms have quite a bit in common. Usually, they all display the application’s name, version number, copyright information, trademarks, and so forth. They may also display a serial number, the name of the registered user, and a web site or phone number where the user can get customer support.

The main difference between these forms is in how the user dismisses them. A splash screen automatically disappears after a few seconds. The user closes an About dialog box by clicking an OK button. A login form closes when the user enters a valid user name and password and then clicks OK. It also closes if the user clicks Cancel, although then it doesn’t display the main application.

Tip 

Sometimes a splash screen is displayed while the application initializes, loads needed data, and otherwise prepares itself for work. In that case, the application removes the splash screen after initialization is complete or a few seconds have passed, whichever comes second.

The forms also differ slightly in the controls they contain. A splash screen needs a Timer control to determine when it’s time to close the form. An About dialog box needs a single OK button. A login form needs TextBoxes to hold the user name and password, two Labels to identify them, and OK and Cancel buttons.

Splash screens and login forms greet the user, so there’s no need to provide both. However, that still leaves you with the task of building two nearly identical forms: splash and About, or login and About. With a little planning, you can use a single form as a splash screen, About dialog box, and login form. At runtime, you can add whichever set of controls is appropriate to the form’s use. Alternatively, you can build the form with all three sets of controls at design time and then hide the ones you don’t need for a particular purpose.

The following code shows how a form can display itself as either a splash screen or an About dialog. The form contains both a Timer named tmrUnload and an OK button named btnAboutOk. The form’s ShowSplash method enables the tmrUnload Timer control and calls Show to display the form. The Timer control’s Interval property was set to 3,000 milliseconds at design time, so its Timer event fires after three seconds and closes the form.

The ShowAbout method makes the btnOk button visible and calls ShowDialog to display the form modally. A modal form holds the application’s focus so the user cannot interact with other parts of the application until the modal form is dismissed. When the user clicks the button, the button’s Click event handler closes the form.

  ' Display as a splash screen. Public Sub ShowSplash()     Me.tmrUnload.Enabled = True ' The Timer close the dialog.     Me.TopMost = True           ' Keep on top of main form.     Me.Show()                   ' Show non-modally. End Sub ' Unload the splash screen. Private Sub tmrUnload_Tick(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles tmrUnload.Tick     Me.Close() End Sub ' Display as an About dialog. Public Sub ShowAbout()     btnOK.Visible = True        ' The OK button closes the dialog.     Me.ShowDialog()             ' Show modally. End Sub ' Close the About dialog. Private Sub btnOK_Click(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles btnOK.Click     Me.Close() End Sub  




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net