- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Reflection;
- namespace Assmest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- this.Text=string.Format(String.Format("关于 {0}", AssemblyTitle));
- }
- public string AssemblyTitle
- {
- get
- {
- // 获取此程序集上的所有 Title 属性
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
- // 如果至少有一个 Title 属性
- if (attributes.Length > 0)
- {
- // 请选择第一个属性
- AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
- // 如果该属性为非空字符串,则将其返回
- if (titleAttribute.Title != "")
- return titleAttribute.Title;
- }
- // 如果没有 Title 属性,或者 Title 属性为一个空字符串,则返回 .exe 的名称
- return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
- }
- }
- }
- }
其他的属性有:
- Assembly.GetExecutingAssembly().GetName().Version.ToString();
- AssemblyDescriptionAttribute
- AssemblyProductAttribute
- AssemblyCopyrightAttribute
- AssemblyCompanyAttribute
转自 http://blog.csdn.net/firetaker/article/details/5544830