65.9K
CodeProject is changing. Read more.
Home

Adding Version Info to your Winforms app in 3 (4) Easy Steps

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.44/5 (12 votes)

Feb 18, 2016

CPOL
viewsIcon

9967

Easily add Version Information to the main form Title bar of your Winforms app

Like a Version

  1. In AssemblyInfo.cs, change this:
    [assembly: AssemblyVersion("1.0.0.0")]

    ...to this:

    [assembly: AssemblyVersion("1.0.*")]
  2. Add "using System.Reflection;" to your main form.
  3. Add this method to your main form:
    private void SetVersionInfo()
    {
        Version versionInfo = Assembly.GetExecutingAssembly().GetName().Version;
        DateTime startDate = new DateTime(2000, 1, 1);
        int diffDays = versionInfo.Build;
        DateTime computedDate = startDate.AddDays(diffDays);
        string lastBuilt = computedDate.ToShortDateString();
        this.Text = string.Format("{0} - Version {1} ({2})", 
                    this.Text, versionInfo.ToString(), lastBuilt);
    }
  4. Finally, in the main form's Load event, add a call to that method:
    private void FormMain_Load(object sender, EventArgs e)
    {
         SetVersionInfo();
    	 . . .
    }

Now when you run your app, it will append the version info to whatever your form's Text property is set to. This helps to verify that users are using the most recent (or most recently released, anyway) version of your app when they call for support. Of course, they never do that, so this tip is completely worthless.