Utilizing Assembly Information for Your Automated Splash Dialog


There are cases when you need to reuse the same splash screen or about box in many applications. If this is the case, this article may be helpful for you. The .NET framework requires applications to provide information about themselves from assembly, such as Title and Version. This allow us to create a common splash screen that is able retrieve and display the application specific information  I used Visual Studio .NET to simplify the steps in this example because it handles class library (dll) neatly.

First, fill in some information about your application in the assembly, the version revision and build number can be generated automatically as default:

Since the splash screen is going to be shared by many applications in your solution, you have to create a class library in your solution:

 



 

Afterward, create a Windows Form in your newly created class library.



A splash dialog usually center itself to the center of screen by setting the StartPosition property to CenterScreen. A timer can be added and enabled if you want it to close itself after certain milliseconds. Text labels for Title and Version are created in this windows form. Also, any click event close the splash dialog.

As we are going to use this class library in the main application, a reference to the class library is required to add.

The splash dialog is open before the main windows display:

static void Main()
{
CommonLib.Splash dlg =
new CommonLib.Splash();
dlg.ShowDialog();
Application.Run(
new Form1());
}

Let's back to the splash dialog. We need to get title and version from the main application in the splash dialog constructor, so here uses GetCalling Assembly which returns the assembly information of the application calling this class library. Getting name and description from the assembly are more or less the same but version is a different story. It is because version belongs to the main assembly information, it is essential and have to cacahe.

using System.Reflection;
...
public SplashForm()
{
...
Assembly assembly = Assembly.GetCallingAssembly();
// name, description and more
object[] attributes = assembly.GetCustomAttributes(true);
foreach (object attribute in attributes)
{
if (attribute is AssemblyTitleAttribute)
labelTitle.Text = ((AssemblyTitleAttribute)attribute).Title;
}
// version
AssemblyName assemblyname = assembly.GetName();
Version assemblyver = assemblyname.Version;
labelVersion.Text = "Version " + assemblyver.ToString();
}

Therefore, you can have a splash dialog for every application by: fill in the assembly, add reference to the class library and call the splash dialog box before the main window starts. Enjoy.

Up Next
    Ebook Download
    View all
    Learn
    View all