Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
18 Feb 2016 1  
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here