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 an 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 display the application’s name, version number, copyright in formation, trademarks, and so forth. They may also display a serial number, the name of the registered user, and a website 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 username and password and then clicks OK. It also closes if the user clicks Cancel, although then it doesn’t display the main application.


REMOVING THE SPLASH
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 to determine when it is time to close the form. An About dialog box needs a single OK button. A login form needs TextBoxes to hold the username 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 in the same application. 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 run time, 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 example program Splash, which is available for download on the book’s website, displays a form either as a splash screen or as an About dialog box:

' Display as a splash screen.
Public Sub ShowSplash()
    Me.tmrUnload.Enabled = True ' The Timer closes 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()  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() Handles btnOK.Click
    Me.Close()
End Sub

The form contains both a Timer named tmrUnload and an OK button named btnAboutOk. The form’s ShowSplash method enables the tmrUnload control and calls Show to display the form. The Timer’s Interval property was set to 3,000 milliseconds at design time, so its Tick 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.0.97