200100301.JPG

AboutForm十分简单,重写了继承自System.Windows.Forms.FormOnLoad方法,而不采用AboutForm_Load来响应窗体的Load事件。

None.gifusing System;
None.gif
using System.Drawing;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Windows.Forms;
None.gif
using System.Diagnostics;
None.gif
using System.Reflection;
None.gif
None.gif
namespace PhotoVision
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// AboutForm 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class AboutForm : System.Windows.Forms.Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private class Consts
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
public const String CompanyLink = "http://phinecos.cnblogs.com/";//开发者网站
ExpandedSubBlockEnd.gif
        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
InBlock.gif            
//省去设计器生成的代码
ExpandedSubBlockEnd.gif
        #endregion

InBlock.gif
InBlock.gif        
private void buttonOk_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{//关闭“关于”窗体
InBlock.gif
            this.Close();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void OnLoad(System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{//重写了OnLoad方法
InBlock.gif

InBlock.gif            
base.OnLoad(e);//引发基类的Load事件
InBlock.gif
InBlock.gif            
//更新版本信息
InBlock.gif
            string delimStr = ".";
InBlock.gif            
char [] delimiter = delimStr.ToCharArray();//分割符
InBlock.gif

InBlock.gif            String[] version 
= Application.ProductVersion.Split(delimiter);//分割版本号信息
InBlock.gif
            this.labelVersion.Text = String.Format("版本号: {0}.{1}.{2}",version[0],version[1],version[2]);
InBlock.gif
InBlock.gif            
//获取此应用程序使用的程序集列表
InBlock.gif

InBlock.gif            AssemblyName[] others 
= System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies();
InBlock.gif            
foreach(AssemblyName aName in others)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.listAssemblies.Items.Add(String.Format("{0} ({1})",aName.Name,aName.Version.ToString()));
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//图片的存放位置
InBlock.gif
            this.textPhotoLocation.Text = Global.DataLocation;
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void linkCompany_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{//启动浏览器
InBlock.gif
                this.linkCompany.LinkVisited = true;
InBlock.gif                System.Diagnostics.Process.Start(Consts.CompanyLink);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(System.Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Trace.WriteLine(ex.Message.ToString());
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

其中,在获取图片的存放位置时使用了一个全局信息类Global。这是一个静态的不可继承的类,提供了很多供其他类读取和修改的全局信息,例如进度的执行情况,图片操作的列表和从应用程序配置文件中读取的配置信息等等。这些全局信息通过Global类提供的静态的公有属性和公有函数来进行访问。

 

下面是AboutForm里用到的Global的属性:

ExpandedBlockStart.gifContractedBlock.gif    /**//// <summary>
InBlock.gif    
/// Global 的摘要说明。
ExpandedBlockEnd.gif    
/// </summary>

None.gif    public sealed class Global
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif{
InBlock.gif        
private Global()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{//构造函数私有使得类成为静态类
InBlock.gif            
//
InBlock.gif            
// TODO: 在此处添加构造函数逻辑
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
public static  String DataLocation
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{//获取指向由指定枚举标识的系统特殊文件夹的路径,其中"Personal"指定用作文档的公共储存库的目录。
InBlock.gif
            get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal),System.Windows.Forms.Application.ProductName);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif


到这里为止,系统里边缘无关的信息都已经了解清楚了,接下来就要开始探索系统中最吸引人的地方---自定义控件和各种面板组件,最后是事件的反升处理(子控件将事件通知给父控件处理),我们会看到就好比是冒泡一样,层层上传事件,这更是系统的精华所在了,此外,GDI+操作更是不可错过的精彩。