Author:水如烟
MS2005自带的About Box内容太少,觉得也不大好看。所以自做一个。这回我不说操作过程了,不清楚的话,可以参考我的另一文《HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2005)》。界面如图:

文件AboutForm.Designer.vb代码:

代码
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Partial Class AboutFormClass AboutForm
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(AboutForm))
Me.AlarmLabel = New System.Windows.Forms.Label
Me.SystemInfoButton = New System.Windows.Forms.Button
Me.OKButton = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.DescriptionTextBox = New System.Windows.Forms.TextBox
Me.UserTextBox = New System.Windows.Forms.TextBox
Me.ICOPictureBox = New System.Windows.Forms.PictureBox
Me.Label3 = New System.Windows.Forms.Label
Me.AssemblyListView = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.ProductLabel = New System.Windows.Forms.Label
Me.ImagePictureBox = New System.Windows.Forms.PictureBox
CType(Me.ICOPictureBox, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.ImagePictureBox, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AlarmLabel
'
Me.AlarmLabel.Location = New System.Drawing.Point(16, 294)
Me.AlarmLabel.Name = "AlarmLabel"
Me.AlarmLabel.Size = New System.Drawing.Size(368, 64)
Me.AlarmLabel.TabIndex = 27
Me.AlarmLabel.Text = "警告:本计算机程序受版权法和国际条约保护。如未经授权而擅自复制或传播本程序(或其中任何部分),将受到严厉的民事和刑事制裁,并将在法律许可的最大限度内受到起诉。"
'
'SystemInfoButton
'
Me.SystemInfoButton.Location = New System.Drawing.Point(408, 326)
Me.SystemInfoButton.Name = "SystemInfoButton"
Me.SystemInfoButton.Size = New System.Drawing.Size(104, 24)
Me.SystemInfoButton.TabIndex = 26
Me.SystemInfoButton.Text = "系统信息(&S)"
'
'OKButton
'
Me.OKButton.DialogResult = System.Windows.Forms.DialogResult.OK
Me.OKButton.Location = New System.Drawing.Point(408, 294)
Me.OKButton.Name = "OKButton"
Me.OKButton.Size = New System.Drawing.Size(104, 24)
Me.OKButton.TabIndex = 25
Me.OKButton.Text = "确定"
'
'GroupBox1
'
Me.GroupBox1.Location = New System.Drawing.Point(8, 278)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(504, 8)
Me.GroupBox1.TabIndex = 24
Me.GroupBox1.TabStop = False
'
'DescriptionTextBox
'
Me.DescriptionTextBox.Location = New System.Drawing.Point(160, 238)
Me.DescriptionTextBox.Multiline = True
Me.DescriptionTextBox.Name = "DescriptionTextBox"
Me.DescriptionTextBox.ReadOnly = True
Me.DescriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.DescriptionTextBox.Size = New System.Drawing.Size(352, 40)
Me.DescriptionTextBox.TabIndex = 23
'
'UserTextBox
'
Me.UserTextBox.BackColor = System.Drawing.SystemColors.Control
Me.UserTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.UserTextBox.Enabled = False
Me.UserTextBox.Location = New System.Drawing.Point(104, 74)
Me.UserTextBox.Multiline = True
Me.UserTextBox.Name = "UserTextBox"
Me.UserTextBox.ReadOnly = True
Me.UserTextBox.Size = New System.Drawing.Size(400, 32)
Me.UserTextBox.TabIndex = 18
'
'ICOPictureBox
'
Me.ICOPictureBox.Location = New System.Drawing.Point(104, 238)
Me.ICOPictureBox.Name = "ICOPictureBox"
Me.ICOPictureBox.Size = New System.Drawing.Size(40, 32)
Me.ICOPictureBox.TabIndex = 22
Me.ICOPictureBox.TabStop = False
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(104, 214)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(96, 16)
Me.Label3.TabIndex = 21
Me.Label3.Text = "产品详细信息:"
'
'AssemblyListView
'
Me.AssemblyListView.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2})
Me.AssemblyListView.Location = New System.Drawing.Point(104, 126)
Me.AssemblyListView.Name = "AssemblyListView"
Me.AssemblyListView.Size = New System.Drawing.Size(400, 80)
Me.AssemblyListView.TabIndex = 20
Me.AssemblyListView.UseCompatibleStateImageBehavior = False
Me.AssemblyListView.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "项目"
Me.ColumnHeader1.Width = 209
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "版本"
Me.ColumnHeader2.Width = 168
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(104, 110)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(120, 16)
Me.Label2.TabIndex = 19
Me.Label2.Text = "引用程序集:"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(104, 58)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(168, 16)
Me.Label1.TabIndex = 17
Me.Label1.Text = "本产品使用权属于:"
'
'ProductLabel
'
Me.ProductLabel.Location = New System.Drawing.Point(104, 14)
Me.ProductLabel.Name = "ProductLabel"
Me.ProductLabel.Size = New System.Drawing.Size(400, 40)
Me.ProductLabel.TabIndex = 16
'
'ImagePictureBox
'
Me.ImagePictureBox.Image = CType(resources.GetObject("ImagePictureBox.Image"), System.Drawing.Image)
Me.ImagePictureBox.Location = New System.Drawing.Point(8, 6)
Me.ImagePictureBox.Name = "ImagePictureBox"
Me.ImagePictureBox.Size = New System.Drawing.Size(88, 272)
Me.ImagePictureBox.TabIndex = 15
Me.ImagePictureBox.TabStop = False
'
'AboutForm
'
Me.AcceptButton = Me.OKButton
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.OKButton
Me.ClientSize = New System.Drawing.Size(520, 365)
Me.Controls.Add(Me.AlarmLabel)
Me.Controls.Add(Me.SystemInfoButton)
Me.Controls.Add(Me.OKButton)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.DescriptionTextBox)
Me.Controls.Add(Me.UserTextBox)
Me.Controls.Add(Me.ICOPictureBox)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.AssemblyListView)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ProductLabel)
Me.Controls.Add(Me.ImagePictureBox)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "AboutForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "AboutForm"
CType(Me.ICOPictureBox, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.ImagePictureBox, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Protected Friend WithEvents AlarmLabel As System.Windows.Forms.Label
Protected Friend WithEvents OKButton As System.Windows.Forms.Button
Protected Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Protected Friend WithEvents DescriptionTextBox As System.Windows.Forms.TextBox
Protected Friend WithEvents UserTextBox As System.Windows.Forms.TextBox
Protected Friend WithEvents ICOPictureBox As System.Windows.Forms.PictureBox
Protected Friend WithEvents Label3 As System.Windows.Forms.Label
Protected Friend WithEvents AssemblyListView As System.Windows.Forms.ListView
Protected Friend WithEvents Label2 As System.Windows.Forms.Label
Protected Friend WithEvents Label1 As System.Windows.Forms.Label
Protected Friend WithEvents ProductLabel As System.Windows.Forms.Label
Protected Friend WithEvents ImagePictureBox As System.Windows.Forms.PictureBox
Protected Friend WithEvents SystemInfoButton As System.Windows.Forms.Button
End Class

文件AboutFormAddtoMainFormClass.vb:
Imports System.Windows.Forms

Public Class AboutFormAddtoMainFormClassClass AboutFormAddtoMainFormClass
Private Const TEXT_DECLARE As String = "关于 {0}"
Private Const PRODUCT_DECLARE As String = "{0} 版本 {1}" & vbCrLf & "{2}. 保留所有权利"
Private Const AUTHORIZATION_DECLARE As String = "{0}" & vbCrLf & "{1}"

Private _AboutForm As AboutForm
Private _MainForm As Windows.Forms.Form
Private _AboutToolStripMenuItem As ToolStripMenuItem


Public ReadOnly Property AboutToolStripMenuItem()Property AboutToolStripMenuItem() As ToolStripMenuItem
Get
Return _AboutToolStripMenuItem
End Get
End Property


Sub New()Sub New(ByVal MainForm As Windows.Forms.Form)
_MainForm = MainForm
Me.Initialize()
Me.AddMenuItemToMainFormMainMenu()
End Sub


Private Sub Initialize()Sub Initialize()
_AboutForm = New AboutForm
With My.Application.Info
_AboutForm.Text = String.Format(Me.TEXT_DECLARE, .Title)
_AboutForm.ProductLabel.Text = String.Format(Me.PRODUCT_DECLARE, .ProductName, .Version, .Copyright)
_AboutForm.UserTextBox.Text = String.Format(Me.AUTHORIZATION_DECLARE, System.Environment.UserName, System.Environment.MachineName)
_AboutForm.DescriptionTextBox.Text = .Description
End With
_AboutForm.ICOPictureBox.Image = CType(_MainForm.Icon.ToBitmap, System.Drawing.Image)

For Each RefAsm As Reflection.AssemblyName In Reflection.Assembly.GetEntryAssembly.GetReferencedAssemblies
_AboutForm.AssemblyListView.Items.Add(New System.Windows.Forms.ListViewItem(New String() {RefAsm.Name, RefAsm.Version.ToString}))
Next

AddHandler _AboutForm.SystemInfoButton.Click, AddressOf SystemInfoButton_Click
End Sub


Protected Overridable Sub SystemInfoButton_Click()Sub SystemInfoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
System.Diagnostics.Process.Start("msinfo32.exe")
End Sub


Private Sub AddMenuItemToMainFormMainMenu()Sub AddMenuItemToMainFormMainMenu()
Dim MenuStrip As MenuStrip = _MainForm.MainMenuStrip
If MenuStrip Is Nothing Then
MenuStrip = New MenuStrip
_MainForm.Controls.Add(MenuStrip)
_MainForm.MainMenuStrip = MenuStrip
End If

Dim HelpToolStripMenuItem As Windows.Forms.ToolStripMenuItem

Dim HelpToolStripItem() As System.Windows.Forms.ToolStripItem
HelpToolStripItem = MenuStrip.Items.Find("HelpToolStripMenuItem", False)
If HelpToolStripItem.Length = 0 Then
HelpToolStripMenuItem = New Windows.Forms.ToolStripMenuItem
HelpToolStripMenuItem.Name = "HelpToolStripMenuItem"
HelpToolStripMenuItem.Text = "帮助(&H)"
MenuStrip.Items.Add(HelpToolStripMenuItem)
Else
HelpToolStripMenuItem = HelpToolStripItem(0)
End If

Dim AboutToolStripItem() As System.Windows.Forms.ToolStripItem
AboutToolStripItem = HelpToolStripMenuItem.DropDownItems.Find("AboutToolStripMenuItem", False)
If AboutToolStripItem.Length = 0 Then
_AboutToolStripMenuItem = New Windows.Forms.ToolStripMenuItem
_AboutToolStripMenuItem.Name = "AboutToolStripMenuItem"
_AboutToolStripMenuItem.Text = String.Format("关于 {0}(&A)", My.Application.Info.Title)
HelpToolStripMenuItem.DropDownItems.Add(_AboutToolStripMenuItem)
AddHandler _AboutToolStripMenuItem.Click, AddressOf AboutToolStripMenuItem_Click
Else
_AboutToolStripMenuItem = AboutToolStripItem(0)
End If
End Sub


Private Sub AboutToolStripMenuItem_Click()Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If _AboutForm Is Nothing OrElse _AboutForm.IsDisposed Then
Me.Initialize()
End If
_AboutForm.ShowDialog(_MainForm)
End Sub

End Class
下面是调用。新建一个工程TestAboutForm,输出为Windows Application.先运行一下,结果当然是这样的:

这次不再是通过添加Inherited Form新项目来调用这个AboutForm,而是直接引用LzmTW.ApplicationBase.Dll,在文件Application.Designer.vb添加代码
MS2005自带的About Box内容太少,觉得也不大好看。所以自做一个。这回我不说操作过程了,不清楚的话,可以参考我的另一文《HOW TO:溅射屏幕(Splash Screen),也叫程序启动画面的制作(.NET2005)》。界面如图:
文件AboutForm.Designer.vb代码:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class AboutFormClass AboutForm
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(AboutForm))
Me.AlarmLabel = New System.Windows.Forms.Label
Me.SystemInfoButton = New System.Windows.Forms.Button
Me.OKButton = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.DescriptionTextBox = New System.Windows.Forms.TextBox
Me.UserTextBox = New System.Windows.Forms.TextBox
Me.ICOPictureBox = New System.Windows.Forms.PictureBox
Me.Label3 = New System.Windows.Forms.Label
Me.AssemblyListView = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.ProductLabel = New System.Windows.Forms.Label
Me.ImagePictureBox = New System.Windows.Forms.PictureBox
CType(Me.ICOPictureBox, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.ImagePictureBox, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AlarmLabel
'
Me.AlarmLabel.Location = New System.Drawing.Point(16, 294)
Me.AlarmLabel.Name = "AlarmLabel"
Me.AlarmLabel.Size = New System.Drawing.Size(368, 64)
Me.AlarmLabel.TabIndex = 27
Me.AlarmLabel.Text = "警告:本计算机程序受版权法和国际条约保护。如未经授权而擅自复制或传播本程序(或其中任何部分),将受到严厉的民事和刑事制裁,并将在法律许可的最大限度内受到起诉。"
'
'SystemInfoButton
'
Me.SystemInfoButton.Location = New System.Drawing.Point(408, 326)
Me.SystemInfoButton.Name = "SystemInfoButton"
Me.SystemInfoButton.Size = New System.Drawing.Size(104, 24)
Me.SystemInfoButton.TabIndex = 26
Me.SystemInfoButton.Text = "系统信息(&S)"
'
'OKButton
'
Me.OKButton.DialogResult = System.Windows.Forms.DialogResult.OK
Me.OKButton.Location = New System.Drawing.Point(408, 294)
Me.OKButton.Name = "OKButton"
Me.OKButton.Size = New System.Drawing.Size(104, 24)
Me.OKButton.TabIndex = 25
Me.OKButton.Text = "确定"
'
'GroupBox1
'
Me.GroupBox1.Location = New System.Drawing.Point(8, 278)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(504, 8)
Me.GroupBox1.TabIndex = 24
Me.GroupBox1.TabStop = False
'
'DescriptionTextBox
'
Me.DescriptionTextBox.Location = New System.Drawing.Point(160, 238)
Me.DescriptionTextBox.Multiline = True
Me.DescriptionTextBox.Name = "DescriptionTextBox"
Me.DescriptionTextBox.ReadOnly = True
Me.DescriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.DescriptionTextBox.Size = New System.Drawing.Size(352, 40)
Me.DescriptionTextBox.TabIndex = 23
'
'UserTextBox
'
Me.UserTextBox.BackColor = System.Drawing.SystemColors.Control
Me.UserTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.UserTextBox.Enabled = False
Me.UserTextBox.Location = New System.Drawing.Point(104, 74)
Me.UserTextBox.Multiline = True
Me.UserTextBox.Name = "UserTextBox"
Me.UserTextBox.ReadOnly = True
Me.UserTextBox.Size = New System.Drawing.Size(400, 32)
Me.UserTextBox.TabIndex = 18
'
'ICOPictureBox
'
Me.ICOPictureBox.Location = New System.Drawing.Point(104, 238)
Me.ICOPictureBox.Name = "ICOPictureBox"
Me.ICOPictureBox.Size = New System.Drawing.Size(40, 32)
Me.ICOPictureBox.TabIndex = 22
Me.ICOPictureBox.TabStop = False
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(104, 214)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(96, 16)
Me.Label3.TabIndex = 21
Me.Label3.Text = "产品详细信息:"
'
'AssemblyListView
'
Me.AssemblyListView.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2})
Me.AssemblyListView.Location = New System.Drawing.Point(104, 126)
Me.AssemblyListView.Name = "AssemblyListView"
Me.AssemblyListView.Size = New System.Drawing.Size(400, 80)
Me.AssemblyListView.TabIndex = 20
Me.AssemblyListView.UseCompatibleStateImageBehavior = False
Me.AssemblyListView.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "项目"
Me.ColumnHeader1.Width = 209
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "版本"
Me.ColumnHeader2.Width = 168
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(104, 110)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(120, 16)
Me.Label2.TabIndex = 19
Me.Label2.Text = "引用程序集:"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(104, 58)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(168, 16)
Me.Label1.TabIndex = 17
Me.Label1.Text = "本产品使用权属于:"
'
'ProductLabel
'
Me.ProductLabel.Location = New System.Drawing.Point(104, 14)
Me.ProductLabel.Name = "ProductLabel"
Me.ProductLabel.Size = New System.Drawing.Size(400, 40)
Me.ProductLabel.TabIndex = 16
'
'ImagePictureBox
'
Me.ImagePictureBox.Image = CType(resources.GetObject("ImagePictureBox.Image"), System.Drawing.Image)
Me.ImagePictureBox.Location = New System.Drawing.Point(8, 6)
Me.ImagePictureBox.Name = "ImagePictureBox"
Me.ImagePictureBox.Size = New System.Drawing.Size(88, 272)
Me.ImagePictureBox.TabIndex = 15
Me.ImagePictureBox.TabStop = False
'
'AboutForm
'
Me.AcceptButton = Me.OKButton
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.CancelButton = Me.OKButton
Me.ClientSize = New System.Drawing.Size(520, 365)
Me.Controls.Add(Me.AlarmLabel)
Me.Controls.Add(Me.SystemInfoButton)
Me.Controls.Add(Me.OKButton)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.DescriptionTextBox)
Me.Controls.Add(Me.UserTextBox)
Me.Controls.Add(Me.ICOPictureBox)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.AssemblyListView)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ProductLabel)
Me.Controls.Add(Me.ImagePictureBox)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "AboutForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "AboutForm"
CType(Me.ICOPictureBox, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.ImagePictureBox, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
Protected Friend WithEvents AlarmLabel As System.Windows.Forms.Label
Protected Friend WithEvents OKButton As System.Windows.Forms.Button
Protected Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Protected Friend WithEvents DescriptionTextBox As System.Windows.Forms.TextBox
Protected Friend WithEvents UserTextBox As System.Windows.Forms.TextBox
Protected Friend WithEvents ICOPictureBox As System.Windows.Forms.PictureBox
Protected Friend WithEvents Label3 As System.Windows.Forms.Label
Protected Friend WithEvents AssemblyListView As System.Windows.Forms.ListView
Protected Friend WithEvents Label2 As System.Windows.Forms.Label
Protected Friend WithEvents Label1 As System.Windows.Forms.Label
Protected Friend WithEvents ProductLabel As System.Windows.Forms.Label
Protected Friend WithEvents ImagePictureBox As System.Windows.Forms.PictureBox
Protected Friend WithEvents SystemInfoButton As System.Windows.Forms.Button
End Class
文件AboutFormAddtoMainFormClass.vb:
Imports System.Windows.Forms
Public Class AboutFormAddtoMainFormClassClass AboutFormAddtoMainFormClass
Private Const TEXT_DECLARE As String = "关于 {0}"
Private Const PRODUCT_DECLARE As String = "{0} 版本 {1}" & vbCrLf & "{2}. 保留所有权利"
Private Const AUTHORIZATION_DECLARE As String = "{0}" & vbCrLf & "{1}"
Private _AboutForm As AboutForm
Private _MainForm As Windows.Forms.Form
Private _AboutToolStripMenuItem As ToolStripMenuItem

Public ReadOnly Property AboutToolStripMenuItem()Property AboutToolStripMenuItem() As ToolStripMenuItem
Get
Return _AboutToolStripMenuItem
End Get
End Property

Sub New()Sub New(ByVal MainForm As Windows.Forms.Form)
_MainForm = MainForm
Me.Initialize()
Me.AddMenuItemToMainFormMainMenu()
End Sub

Private Sub Initialize()Sub Initialize()
_AboutForm = New AboutForm
With My.Application.Info
_AboutForm.Text = String.Format(Me.TEXT_DECLARE, .Title)
_AboutForm.ProductLabel.Text = String.Format(Me.PRODUCT_DECLARE, .ProductName, .Version, .Copyright)
_AboutForm.UserTextBox.Text = String.Format(Me.AUTHORIZATION_DECLARE, System.Environment.UserName, System.Environment.MachineName)
_AboutForm.DescriptionTextBox.Text = .Description
End With
_AboutForm.ICOPictureBox.Image = CType(_MainForm.Icon.ToBitmap, System.Drawing.Image)
For Each RefAsm As Reflection.AssemblyName In Reflection.Assembly.GetEntryAssembly.GetReferencedAssemblies
_AboutForm.AssemblyListView.Items.Add(New System.Windows.Forms.ListViewItem(New String() {RefAsm.Name, RefAsm.Version.ToString}))
Next
AddHandler _AboutForm.SystemInfoButton.Click, AddressOf SystemInfoButton_Click
End Sub

Protected Overridable Sub SystemInfoButton_Click()Sub SystemInfoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
System.Diagnostics.Process.Start("msinfo32.exe")
End Sub

Private Sub AddMenuItemToMainFormMainMenu()Sub AddMenuItemToMainFormMainMenu()
Dim MenuStrip As MenuStrip = _MainForm.MainMenuStrip
If MenuStrip Is Nothing Then
MenuStrip = New MenuStrip
_MainForm.Controls.Add(MenuStrip)
_MainForm.MainMenuStrip = MenuStrip
End If
Dim HelpToolStripMenuItem As Windows.Forms.ToolStripMenuItem
Dim HelpToolStripItem() As System.Windows.Forms.ToolStripItem
HelpToolStripItem = MenuStrip.Items.Find("HelpToolStripMenuItem", False)
If HelpToolStripItem.Length = 0 Then
HelpToolStripMenuItem = New Windows.Forms.ToolStripMenuItem
HelpToolStripMenuItem.Name = "HelpToolStripMenuItem"
HelpToolStripMenuItem.Text = "帮助(&H)"
MenuStrip.Items.Add(HelpToolStripMenuItem)
Else
HelpToolStripMenuItem = HelpToolStripItem(0)
End If
Dim AboutToolStripItem() As System.Windows.Forms.ToolStripItem
AboutToolStripItem = HelpToolStripMenuItem.DropDownItems.Find("AboutToolStripMenuItem", False)
If AboutToolStripItem.Length = 0 Then
_AboutToolStripMenuItem = New Windows.Forms.ToolStripMenuItem
_AboutToolStripMenuItem.Name = "AboutToolStripMenuItem"
_AboutToolStripMenuItem.Text = String.Format("关于 {0}(&A)", My.Application.Info.Title)
HelpToolStripMenuItem.DropDownItems.Add(_AboutToolStripMenuItem)
AddHandler _AboutToolStripMenuItem.Click, AddressOf AboutToolStripMenuItem_Click
Else
_AboutToolStripMenuItem = AboutToolStripItem(0)
End If
End Sub

Private Sub AboutToolStripMenuItem_Click()Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If _AboutForm Is Nothing OrElse _AboutForm.IsDisposed Then
Me.Initialize()
End If
_AboutForm.ShowDialog(_MainForm)
End Sub
End Class下面是调用。新建一个工程TestAboutForm,输出为Windows Application.先运行一下,结果当然是这样的:
这次不再是通过添加Inherited Form新项目来调用这个AboutForm,而是直接引用LzmTW.ApplicationBase.Dll,在文件Application.Designer.vb添加代码
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.TestAboutForm.Form1
'LzmTW 添加如下代码
Dim AboutForm As New LzmTW.ApplicationBase.AboutFormAddtoMainFormClass(Me.MainForm)
End Sub
运行,结果如图:Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.TestAboutForm.Form1
'LzmTW 添加如下代码
Dim AboutForm As New LzmTW.ApplicationBase.AboutFormAddtoMainFormClass(Me.MainForm)
End Sub
