/// Listing 1 /// Complete Code for AboutForm.cs using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Reflection; using System.Text; namespace AboutForm { /// /// Summary description for AboutForm. /// public class AboutForm : System.Windows.Forms.Form { private System.Windows.Forms.PictureBox IconBox; private System.Windows.Forms.Label TextArea; private System.Windows.Forms.Button OKButton; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private AboutForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.IconBox = new System.Windows.Forms.PictureBox(); this.TextArea = new System.Windows.Forms.Label(); this.OKButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // IconBox // this.IconBox.Location = new System.Drawing.Point(24, 24); this.IconBox.Name = "IconBox"; this.IconBox.Size = new System.Drawing.Size(56, 56); this.IconBox.SizeMode = PictureBoxSizeMode.CenterImage; this.IconBox.TabIndex = 0; this.IconBox.TabStop = false; // // TextArea // this.TextArea.Location = new System.Drawing.Point(96, 24); this.TextArea.Name = "TextArea"; this.TextArea.Size = new System.Drawing.Size(208, 56); this.TextArea.TabIndex = 1; this.TextArea.Text = "label1"; this.TextArea.TextAlign = ContentAlignment.MiddleLeft; // // OKButton // this.OKButton.Location = new System.Drawing.Point(120, 96); this.OKButton.Name = "OKButton"; this.OKButton.TabIndex = 2; this.OKButton.Text = "OK"; this.OKButton.Click += new System.EventHandler(this.OKButton_Click); // // AboutForm // this.AcceptButton = this.OKButton; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(320, 128); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.OKButton, this.TextArea, this.IconBox}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(326, 160); this.MinimizeBox = false; this.MinimumSize = new System.Drawing.Size(326, 160); this.Name = "AboutForm"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.Text = "About: "; this.Load += new System.EventHandler(this.AboutForm_Load); this.ResumeLayout(false); } #endregion private void AboutForm_Load(object sender, System.EventArgs e) { Icon i = Owner.Icon; this.Icon = i; IconBox.Image = i.ToBitmap(); Assembly ThisAssembly = Assembly.GetExecutingAssembly(); AssemblyName ThisAssemblyName = ThisAssembly.GetName(); string FriendlyVersion = string.Format( "{0:D}-{1:D2}" , ThisAssemblyName.Version.Major , ThisAssemblyName.Version.Minor ); Array Attributes = ThisAssembly.GetCustomAttributes( false ); string Title = "Unknown Application"; string Copyright = "Unknown Copyright"; foreach ( object o in Attributes ) { if ( o is AssemblyTitleAttribute ) { Title = ((AssemblyTitleAttribute)o).Title; } else if ( o is AssemblyCopyrightAttribute ) { Copyright = ((AssemblyCopyrightAttribute)o).Copyright; } } this.Text = "About " + Title; StringBuilder sb = new StringBuilder(""); sb.Append( Title ); sb.Append( " Version " ); sb.Append( FriendlyVersion ); sb.Append( " (" ); sb.Append( ThisAssemblyName.Version.ToString() ); sb.Append( ")\n\n" ); sb.Append( Copyright ); TextArea.Text = sb.ToString(); } private void OKButton_Click(object sender, System.EventArgs e) { Close(); } internal static void ShowAboutForm( IWin32Window Owner ) { System.Diagnostics.Debug.Assert( ( Owner != null ) || !( Owner is IWin32Window ) , "AboutForm.AboutForm.ShowAboutForm MUST be supplied with a valid parent window" ); AboutForm form = new AboutForm(); form.ShowDialog( Owner ); } } }