frmSplash Form
The form frmSplash is a splash screen. It is added to the project if you specify a splash screen at application startup in the VB Application Wizard. After being upgraded, this form has two problems. First, as the frmAbout form does, frmSplash inserts the application version into a label. As we discussed in the earlier section on App.Revision, you should replace the version code in Form_Load. The following Visual Basic 6 code
lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." _ & App.Revision
upgrades to
lblVersion.Text = "Version " & _ System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMajorPart _ & "." & System.Diagnostics.FileVersionInfo.GetVersionInfo( _ System.Reflection.Assembly.GetExecutingAssembly.Location _ ).FileMinorPart & "." & App.Revision
Replace this code with the following:
lblVersion.Text = "Version " & Application.ProductVersion
The second problem is something new. Applications with a splash screen perform a series of steps in Sub Main to
Show the frmSplash form.
Refresh the frmSplash form (forcing the form to be fully painted).
Load the frmMain form.
Unload the frmSplash form.
And finally, show the frmMain form.
Here is the code that performs this series of steps:
Sub Main() frmSplash.Show frmSplash.Refresh Set fMainForm = New frmMain Load fMainForm Unload frmSplash fMainForm.Show End Sub
After upgrading, this code looks like the following:
Public Sub Main() frmSplash.DefInstance.Show() frmSplash.DefInstance.Refresh() fMainForm.DefInstance = New frmMain 'UPGRADE_ISSUE: Load statement is not supported. Load(fMainForm) frmSplash.DefInstance.Close() System.Windows.Forms.Application.Run(fMainForm.DefInstance) End Sub
This code causes a compile error because the Load statement is not supported in Visual Basic .NET. To fix the error, remove the Load(fMainForm) statement; the application will work normally. The updated Sub Main event will look like this:
Public Sub Main() frmSplash.DefInstance.Show() frmSplash.DefInstance.Refresh() fMainForm.DefInstance = New frmMain frmSplash.DefInstance.Close() System.Windows.Forms.Application.Run(fMainForm.DefInstance) End Sub