Home > Posts > HowTo: Display version information on WinForm title

HowTo: Display version information on WinForm title

This is my contribution to
http://stackoverflow.com/questions/7178725/version-number-in-winform-form-text

I’m using the following at the WinForm of the WebCapture tool I’m making for ClipFlair:

public MainForm()
{
  InitializeComponent();
  Version version = Assembly.GetExecutingAssembly().GetName().Version;
  Text = Text + " " + version.Major + "." + version.Minor + 
" (build " + version.Build + ")"; //change form title }

Not showing revision number to the user, build number is enough technical info

Make sure your AssemblyInfo.cs ends in the following (remove the version it has there by default) for VisualStudio to autoincrement build and revision number. You have to update major and minor versions yourself at every release (update major version for new features, minor version when you do just fixes):

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build
// and Revision Number by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.*")]

Update: Since now WebCapture is ClickOnce-deployed from the web (also has nice autoupdate support thanks to ClickOnce) and I want to avoid user confusion by showing the published version of the app (as the ClickOnce installation page does) on the WinForm titlebar, I now use the following code instead, based on a relevant post I found on the web:

public MainForm()

{

  InitializeComponent();

  ShowVersion();

}

private void ShowVersion()

{

  Version version = (ApplicationDeployment.IsNetworkDeployed)?

    ApplicationDeployment.CurrentDeployment.CurrentVersion :

    Assembly.GetExecutingAssembly().GetName().Version;

    //if network deployed show published version (as the web install page)

    
  Text = Text + " " + version.Major + "." + version.Minor + "."

                     + version.Build + "." + version.Revision;

                       //change form title

}

BTW, speaking of ClickOnce, I noticed that if at the autoupdate dialog shown when you launch the app from its desktop shortcut (and there’s a new version available) you press “Skip”, it won’t offer you this update anymore when you launch an app (I hope that when an even newer update is there it will prompt you), but you can override that behaviour by going to the installation page for your ClickOnce app (where you installed it from in the first place) and press the “Install” button there.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: