一个通用的类似微软产品的About

类别:.NET开发 点击:0 评论:0 推荐:

效果图


项目的AssemblyInfo.vb内容

Imports System.Reflection

<Assembly: AssemblyTitle("水如烟管理系统")>

<Assembly: AssemblyDescription("补充原有功能,以查询和输出报表为主" & microsoft.VisualBasic.ControlChars.crlf & "具体对数据的操作还是在DOS系统下的FOXPRO 2.6版管理系统")>

<Assembly: AssemblyCompany("")>

<Assembly: AssemblyProduct("")>

<Assembly: AssemblyCopyright("Copyright (C) 2003 LzmTW")>

<Assembly: CLSCompliant(True)>

<Assembly: AssemblyVersion("1.0.0.0")>

 

在程序主界面中调用方法:

    Private Sub AboutMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutMenuItem.Click

        Dim FrmAbout As New LzmTW.About.AboutForm(Me)

        FrmAbout.AboutInfo.Image = Image.FromFile(Application.StartupPath & "\..\sea.jpg")

        FrmAbout.InitAboutInfo()

        FrmAbout.ShowDialog()

    End Sub

以下是About类

 

Imports System.Diagnostics

Imports System.Reflection

Namespace LzmTW.About  '参考者,请保持本引用空间名称

    Public Class AboutForm

        Inherits System.Windows.Forms.Form

 

#Region " Windows 窗体设计器生成的代码 "

 

        Public Sub New(ByVal MainForm As Form)

            MyBase.New()

 

            '该调用是 Windows 窗体设计器所必需的。

            InitializeComponent()

 

            '在 InitializeComponent() 调用之后添加任何初始化

            m_AboutInfo = New AboutInfo(MainForm)

            m_AboutInfo.Icon = MainForm.Icon

            '更新界面

            InitAboutInfo()

        End Sub

 

        '窗体重写 dispose 以清理组件列表。

        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

            If disposing Then

                If Not (components Is Nothing) Then

                    components.Dispose()

                End If

            End If

            MyBase.Dispose(disposing)

        End Sub

 

        'Windows 窗体设计器所必需的

        Private components As System.ComponentModel.IContainer

 

        '注意: 以下过程是 Windows 窗体设计器所必需的

        '可以使用 Windows 窗体设计器修改此过程。

        '不要使用代码编辑器修改它。

        Friend WithEvents ProductLabel As System.Windows.Forms.Label

        Friend WithEvents Label1 As System.Windows.Forms.Label

        Friend WithEvents Label2 As System.Windows.Forms.Label

        Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader

        Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader

        Friend WithEvents Label3 As System.Windows.Forms.Label

        Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox

        Friend WithEvents OKButton As System.Windows.Forms.Button

        Friend WithEvents SystemInfoButton As System.Windows.Forms.Button

        Friend WithEvents AlarmLabel As System.Windows.Forms.Label

        Friend WithEvents ImagePictureBox As System.Windows.Forms.PictureBox

        Friend WithEvents UserTextBox As System.Windows.Forms.TextBox

        Friend WithEvents AssemblyListView As System.Windows.Forms.ListView

        Friend WithEvents ICOPictureBox As System.Windows.Forms.PictureBox

        Friend WithEvents DescriptionTextBox As System.Windows.Forms.TextBox

        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(AboutForm))

            Me.ImagePictureBox = New System.Windows.Forms.PictureBox

            Me.ProductLabel = New System.Windows.Forms.Label

            Me.Label1 = New System.Windows.Forms.Label

            Me.UserTextBox = New System.Windows.Forms.TextBox

            Me.Label2 = 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.Label3 = New System.Windows.Forms.Label

            Me.ICOPictureBox = New System.Windows.Forms.PictureBox

            Me.DescriptionTextBox = New System.Windows.Forms.TextBox

            Me.GroupBox1 = New System.Windows.Forms.GroupBox

            Me.OKButton = New System.Windows.Forms.Button

            Me.SystemInfoButton = New System.Windows.Forms.Button

            Me.AlarmLabel = New System.Windows.Forms.Label

            Me.SuspendLayout()

            '

            'ImagePictureBox

            '

            Me.ImagePictureBox.Location = New System.Drawing.Point(8, 8)

            Me.ImagePictureBox.Name = "ImagePictureBox"

            Me.ImagePictureBox.Size = New System.Drawing.Size(88, 272)

            Me.ImagePictureBox.TabIndex = 0

            Me.ImagePictureBox.TabStop = False

            '

            'ProductLabel

            '

            Me.ProductLabel.Location = New System.Drawing.Point(104, 16)

            Me.ProductLabel.Name = "ProductLabel"

            Me.ProductLabel.Size = New System.Drawing.Size(400, 40)

            Me.ProductLabel.TabIndex = 1

            '

            'Label1

            '

            Me.Label1.Location = New System.Drawing.Point(104, 60)

            Me.Label1.Name = "Label1"

            Me.Label1.Size = New System.Drawing.Size(168, 16)

            Me.Label1.TabIndex = 3

            Me.Label1.Text = "本产品使用权属于:"

            '

            '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, 76)

            Me.UserTextBox.Multiline = True

            Me.UserTextBox.Name = "UserTextBox"

            Me.UserTextBox.ReadOnly = True

            Me.UserTextBox.Size = New System.Drawing.Size(400, 32)

            Me.UserTextBox.TabIndex = 4

            Me.UserTextBox.Text = ""

            '

            'Label2

            '

            Me.Label2.Location = New System.Drawing.Point(104, 112)

            Me.Label2.Name = "Label2"

            Me.Label2.Size = New System.Drawing.Size(120, 16)

            Me.Label2.TabIndex = 5

            Me.Label2.Text = "引用程序集:"

            '

            'AssemblyListView

            '

            Me.AssemblyListView.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2})

            Me.AssemblyListView.Location = New System.Drawing.Point(104, 128)

            Me.AssemblyListView.Name = "AssemblyListView"

            Me.AssemblyListView.Size = New System.Drawing.Size(400, 80)

            Me.AssemblyListView.TabIndex = 6

            Me.AssemblyListView.View = System.Windows.Forms.View.Details

            '

            'ColumnHeader1

            '

            Me.ColumnHeader1.Text = "项目"

            Me.ColumnHeader1.Width = 150

            '

            'ColumnHeader2

            '

            Me.ColumnHeader2.Text = "版本"

            Me.ColumnHeader2.Width = 150

            '

            'Label3

            '

            Me.Label3.Location = New System.Drawing.Point(104, 216)

            Me.Label3.Name = "Label3"

            Me.Label3.Size = New System.Drawing.Size(96, 16)

            Me.Label3.TabIndex = 7

            Me.Label3.Text = "产品详细信息:"

            '

            'ICOPictureBox

            '

            Me.ICOPictureBox.Location = New System.Drawing.Point(104, 240)

            Me.ICOPictureBox.Name = "ICOPictureBox"

            Me.ICOPictureBox.Size = New System.Drawing.Size(40, 32)

            Me.ICOPictureBox.TabIndex = 8

            Me.ICOPictureBox.TabStop = False

            '

            'DescriptionTextBox

            '

            Me.DescriptionTextBox.Location = New System.Drawing.Point(160, 240)

            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 = 9

            Me.DescriptionTextBox.Text = ""

            '

            'GroupBox1

            '

            Me.GroupBox1.Location = New System.Drawing.Point(8, 280)

            Me.GroupBox1.Name = "GroupBox1"

            Me.GroupBox1.Size = New System.Drawing.Size(504, 8)

            Me.GroupBox1.TabIndex = 11

            Me.GroupBox1.TabStop = False

            '

            'OKButton

            '

            Me.OKButton.DialogResult = System.Windows.Forms.DialogResult.OK

            Me.OKButton.Location = New System.Drawing.Point(408, 296)

            Me.OKButton.Name = "OKButton"

            Me.OKButton.Size = New System.Drawing.Size(104, 24)

            Me.OKButton.TabIndex = 12

            Me.OKButton.Text = "确定"

            '

            'SystemInfoButton

            '

            Me.SystemInfoButton.Location = New System.Drawing.Point(408, 328)

            Me.SystemInfoButton.Name = "SystemInfoButton"

            Me.SystemInfoButton.Size = New System.Drawing.Size(104, 24)

            Me.SystemInfoButton.TabIndex = 13

            Me.SystemInfoButton.Text = "系统信息(&S)"

            '

            'AlarmLabel

            '

            Me.AlarmLabel.Location = New System.Drawing.Point(16, 296)

            Me.AlarmLabel.Name = "AlarmLabel"

            Me.AlarmLabel.Size = New System.Drawing.Size(368, 64)

            Me.AlarmLabel.TabIndex = 14

            '

            'AboutForm

            '

            Me.AcceptButton = Me.OKButton

            Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

            Me.ClientSize = New System.Drawing.Size(522, 370)

            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.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)

            Me.Name = "AboutForm"

            Me.ShowInTaskbar = False

            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

            Me.Text = "Form1"

            Me.ResumeLayout(False)

 

        End Sub

 

#End Region

 

        Private m_AboutInfo As AboutInfo

        Public ReadOnly Property AboutInfo() As AboutInfo

            Get

                Return m_AboutInfo

            End Get

        End Property

        '如果对有关信息进行了更新,调用此方法来更新界面

        Public Sub InitAboutInfo()

            With m_AboutInfo

                Me.ProductLabel.Text = .Product

                Me.UserTextBox.Text = .Authorization

                Me.DescriptionTextBox.Text = .Description

                For Each Item As Object In .AssemblyItems

                    Me.AssemblyListView.Items.Add(New ListViewItem(CType(Item, String())))

                Next

                Me.ImagePictureBox.Image = .Image

                Me.ICOPictureBox.Image = CType(.Icon.ToBitmap, Image)

                Me.AlarmLabel.Text = .Alarm

                Me.Text = .Text

            End With

        End Sub

        '调用系统信息

        Private Sub SystemInfoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemInfoButton.Click

            System.Diagnostics.Process.Start("msinfo32.exe")

        End Sub

    End Class

 

    Public Class AboutInfo

        Private m_Title As String

        Private m_Description As String

        Private m_Product As String

        Private m_Copyright As String

        Private m_Version As String

        Private m_User As String

        Private m_Organization As String

 

        Private m_Image As Image

        Private m_Icon As System.Drawing.Icon

        Private m_Alarm As String = _

        "警告:本计算机程序受版权法和国际条约保护。" & _

        "如未经授权而擅自复制或传播本程序(或其中任何部分),将受到严厉的民事和刑事制裁," & _

        "并将在法律许可的最大限度内受到起诉。"

        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 mMainForm As Form

        Private mAssemblyNameVersion As ArrayList

        'MainForm为主窗体

        Sub New(ByVal MainForm As Form)

            mMainForm = MainForm

            Initialize()

        End Sub

        Private Sub Initialize()

            '取引用的程序集名称和版本

            mAssemblyNameVersion = New ArrayList

            For Each RefAsm As AssemblyName In [Assembly].GetExecutingAssembly.GetReferencedAssemblies

                mAssemblyNameVersion.Add(New String() {RefAsm.Name, RefAsm.Version.ToString})

            Next

 

            '从MainForm所在项目的AssemblyInfo.vb文件中取有关项目信息

            Dim t As Type = mMainForm.GetType

            '取程序集标题

            m_Title = CType(t.Assembly.GetCustomAttributes(GetType(AssemblyTitleAttribute), False)(0), AssemblyTitleAttribute).Title

            '取程序描述信息

            m_Description = CType(t.Assembly.GetCustomAttributes(GetType(AssemblyDescriptionAttribute), False)(0), AssemblyDescriptionAttribute).Description

            '取版权信息

            m_Copyright = CType(t.Assembly.GetCustomAttributes(GetType(AssemblyCopyrightAttribute), False)(0), AssemblyCopyrightAttribute).Copyright

            '取版本信息

            m_Version = t.Assembly.GetName.Version.ToString

 

            '授权信息如是注册形式请按具体情况读取

            m_User = System.Environment.UserName

            m_Organization = System.Environment.MachineName

        End Sub

        Public ReadOnly Property Description() As String

            Get

                Return m_Description

            End Get

        End Property

        Public WriteOnly Property User() As String

            Set(ByVal Value As String)

                m_User = Value

            End Set

        End Property

        Public WriteOnly Property Organization() As String

            Set(ByVal Value As String)

                m_Organization = Value

            End Set

        End Property

        Public Property Image() As Image

            Get

                Return m_Image

            End Get

            Set(ByVal Value As Image)

                m_Image = Value

            End Set

        End Property

        Public Property Icon() As Icon

            Get

                Return m_Icon

            End Get

            Set(ByVal Value As Icon)

                m_Icon = Value

            End Set

        End Property

        Public Property Alarm() As String

            Get

                Return m_Alarm

            End Get

            Set(ByVal Value As String)

                m_Alarm = Value

            End Set

        End Property

        Public ReadOnly Property AssemblyItems() As Array

            Get

                Return mAssemblyNameVersion.ToArray

            End Get

        End Property

        Public ReadOnly Property Text() As String

            Get

                Return String.Format(TEXT_DECLARE, m_Title)

            End Get

        End Property

        Public ReadOnly Property Product() As String

            Get

                Return String.Format(PRODUCT_DECLARE, m_Title, m_Version, m_Copyright)

            End Get

        End Property

        Public ReadOnly Property Authorization() As String

            Get

                Return String.Format(AUTHORIZATION_DECLARE, m_User, m_Organization)

            End Get

        End Property

    End Class

End Namespace

本文地址:http://com.8s8s.com/it/it42866.htm