家庭理财软件测评结果

目前工作比较紧张,客户的程序还没有完全修改完成,所以长话短说,只说结果。

前几天下载了很多的家庭理财软件、流水帐软件进行测试。这类软件的测试以前也作过,最终因为不懂财务知识,而且当时(学生)对资金管理有限,所以那时保留了“小账本”这个程序。经过这一年的工作,还有日常生活中对理财软件的要求,最近又对家庭理财软件进行重新测评。

这次测评最初选择的程序很多,国内的财智家庭理财、家财通、理财好轻松,国外的Money、Quicken、AceMoney等14款软件。经过了初步审核,排除了国外软件在语言上的障碍,最终保留了两款软件。

家庭理财软件的目的:
1、能记流水帐
2、能对放置在不同位置的资金进行分别管理
3、有详细的图表
4、能实现收支预算
5、能对股票、基金、保险等的投资进行管理

最终结果:
第一名:财智家庭理财4.6
第二名:家财通普及版1.32b

财智家庭理财功能十分强大,能满足以上5点的要求,初步评测结果为第一名
家财通分为3个版本:普及版、标准版、专业版。其中普及版能实现以上1-3项功能,标准版和专业版没有进行测试。

注册收费:
财智家庭理财4.6,注册费用98元,目前有注册机可供使用,http://www.imoney.com.cn
家财通普及版1.32b,普及版、标准版和专业版的报价分别为28元、58元和98元,目前家财通搞活动,可以在2005年免费注册普及版,不错哦。http://www.mymoneymaster.com/

以上只是在正式使用这两款软件前的基本测试,我准备在未来的1-2个月同时使用这两套软件,看看到底哪个最能满足我的需求。

Share
Posted in 软件 | 6 Comments

坚决抵制日货

目前反日情绪日渐高涨,应当人人行动起来,反对日本加入常任理事国,反对日本篡改教科书。

最基本的反日行动就是抵制日货,在有替代品的情况下坚决不买日货,让日本逐渐失去中国市场。

以前比较看好佳能和尼康的DC,现在开始关注柯达了。柯达 DX7590十分不错,攒点钱,买下。哈哈
小日本的东西就不用买了。

Share
Posted in 生活 | 1 Comment

临安游玩的照片

这个周末公司组织去临安游玩,下面是排的照片,相机不好,有点曝光过度,有的还模糊(这个估计是相机上的拍摄方式不对导致的,设定成“人像”,很多都是拍得风景,导致图片模糊,还有就是有些风景是在行使中的汽车上拍的)

进山之后拍的
title

title

title

title

这个是“高山云雾茶”茶树
title

这是太湖源头山里的风景,水很清澈的
title

title

这是采茶人,和印象中的采茶姑娘相差甚远
title

这是快接近山顶时一条基本上没人的小道的尽头
title

title

这个就是传说中尝百草的神农了
title

这些是“神龙山”景观
title
title
title

在下山时找到的一条“千足虫”,这条虫子居然能在水底行走,后来为了发扬人道主义精神,将其放生
title

这次去还有一个小小的收获,就是拔了几根竹笋回来。哈哈

Share
Posted in 生活 | 1 Comment

让小字体更清晰

这个方法是从微软的邮件里发现的。

以往看微软发送的邮件,里面很多小字体,大概是8px大小的,看起来很不舒服,这次微软提供了一个方法。

在桌面上点击鼠标右键,选择”属性“,依次点击”外观“–”效果“,点击”是用下列方式使屏幕字体的边缘平滑“的下拉框,选择”清晰“。点击确定。

OK,让我们看看效果。

之前的效果

之后的效果

这么操作之后,一些很细的文字就会被转换成稍微粗一点的,看起来还挺舒服,这个是针对文字在显示上的改变,对在图片上写的字没有影响。

Share
Posted in 操作系统 | Leave a comment

这个周末去临安玩

周末公司组织去临安玩,就在杭州附近,听说山水秀丽。
回来把照片传上来,欣赏一下。

Share
Posted in 生活 | Leave a comment

Gmail出现了盼望已久的中文界面

2个月前就听说Gmail出现了中文界面,只是听说,看了截图,但自己始终没弄出来。

上个星期登陆Gmail,发现它的容量是逐渐增长的,真的是很特别。

今天再次登陆Gmail,到设置里看看,里面多了一个预言选项,选择了简体中文,重新登陆,发现Gmail界面已经成为熟悉的中文了。

以前通过Gmail发送附件,几乎没有成功过,发送一个75K的小附件都不行,提示错误。今天下午发送了一个9M的附件,顺利发出。目前在测试发送一个15M的附件,如果能发送成功,说明Gmail已经很实用了。

Share
Posted in 软件 | Leave a comment

用C#杀死进程

哈哈,太强了,在CSDN上看Dispose的作用,发现了一个列出系统进程的方法。

foreach(Process my in System.Diagnostics.Process.GetProcesses())
{
    b+="\n" + my.ProcessName;
}

这样b里面就包含了系统中所有的进程名称了。

如果想杀进程,容易,只要这样:

using System.Diagnostics;
//404为进程ID,在我的电脑上,目前这个进程ID是Smss.exe的。
//哈哈,系统关键进程,用Windows自带的进程管理器是杀不掉的。
Process a=Process.GetProcessById(404);
a.Kill();    //当然是杀死进程了

这样,系统关键进程就被干掉,你会发现Xp蓝屏,只能按机箱上的复位按钮了。

Share
Posted in 编程 | Leave a comment

在win2000中改MAC地址的方法

打开注册表编辑器,找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}子键,

在该子键下的0000,0001,0002等分支中查找DriverDesc,在在0000子键下天一个字符串项,命名为NetworkAddress,键值设为修改后的MAC地址

,要求为连续的12个16进制数,如1234567890AB。然后在0000下的NDI\params中加一项名为NetworkAddress的子键,在该子键下添加名为defau

lt的字符串,键值为修改后的MAC地址,与上面的数值相同。在NetworkAddress的主键下继续添加命名为ParamDesc的字符串,其作用是制定Net

workAddress主键的描述,其值可为“MAC 地址”,这样以后打开网络属性,双击相应的网卡会发现有一个高级设置,其下坐在“MAC地址”的

选项,在此修改MAC地址就可以了,修改后需重启。

Windows环境:
用dos,8139的可以改,用realtek的pg8139.exe,比如 是8139c网卡,就改写8139c.cfg文件,第一行就是网卡mac,想怎么改就怎么改

这个方法是以前在网上搜得,具体没试过,不过从理论上讲应该是行不通的,不可能通过修改注册表来修改网卡的MAC地址。
如果这个方法行得通,说明这是修改Windows封装包时的MAC地址。但是如果对方主机根据这个地址应答,那么这张网卡应该是接收不到的,因为对方发送的MAC地址与硬件本身的不一致。如果能接收,估计是网卡已经工作在了混杂模式,这样,发往任何地址的数据包,该网卡都会收到,经过Windows的分析,将目的MAC地址与注册表里的地址比较,如果相符,则处理相应的请求,如果不符就将之丢弃。
这是我的猜测,具体还没试过,等试过之后再下定论吧。

Share
Posted in 操作系统 | Leave a comment

转载:实作 Dispose 方法

型别的 Dispose 方法应该释放它所拥有的所有资源。它也应该藉由呼叫其基底型别之父型别的 Dispose 方法,来释放其基底型别所拥有的所有资源。这个父型别的 Dispose 方法应该释放它所拥有的所有资源,并且接续呼叫其父型别的 Dispose 方法,依照这个模式传播到整个基底型别的阶层架构。若要确保资源永远都能适当地清除,Dispose 方法应该能够被重复呼叫多次而不会掷回例外情况 (Exception)。

Dispose 方法应该呼叫它正在处置之物件的 GC.SuppressFinalize 方法。如果物件目前正在最终处理伫列,GC.SuppressFinalize 会防止它的 Finalize 方法被呼叫。请记住,执行 Finalize 方法对效能会有很大影响。如果 Dispose 方法已经执行完清除物件的工作,那麽就不需要再让记忆体回收行程去呼叫该物件的 Finalize 方法。

下列程式码范例的目的是要说明一种可能的设计模式,这种模式可为封装 Unmanaged 资源的类别实作 Dispose 方法。您可能会发现这个模式用起来相当方便,因为它已实作於整个 .NET Framework。不过,这并不是 Dispose 方法唯一可能的实作。

资源类别通常是从复杂的原生类别或 API 衍生而来,因此必须依照情况加以自订。请将这个程式码模式当作建立资源类别的起始点,并且根据您正在封装的资源,提供必要的自订。您不能编译这个范例并直接在应用程式中使用它。

在这个范例中,基底类别 BaseResource 会实作一个可让类别使用者呼叫的公用 Dispose 方法。它会接着呼叫 virtual Dispose(bool disposing) 方法 (在 Visual Basic 中为 virtual Dispose(disposing As Boolean))。根据呼叫端的识别 (Identity) 来传递true 或 false。物件的适当清除程式码会在这个虚拟 Dispose 方法中执行。

Dispose(bool disposing) 可在两种不同的案例中执行。如果 disposing 等於 true,表示方法是由使用者的程式码直接或间接呼叫的,因此可以处置 Managed 和 Unmanaged 资源。如果 disposing 等於 false,表示方法是由 Runtime 从完成项内部呼叫的,因此只能处置 Unmanaged 资源。当物件正在执行它的最终处理程式码时,它不可以参考其他物件,因为完成项不会依照任何特定顺序执行。如果正在执行的完成项参考的另一个物件已经做过最终处理,那麽正在执行的完成项将会失败。

基底类别提供 Finalize 方法或解构函式,做为万一没有呼叫 Dispose 时的防护措施。Finalize 方法会呼叫使用参数传递 false 的 Dispose 方法。您不可以在 Finalize 方法内重新建立 Dispose 清除程式码。呼叫 Dispose(false) 对於程式码的可读性和可维护性是最佳方式。

MyResourceWrapper 类别说明了如何从使用 Dispose 实作资源管理的类别中衍生一个类别的方法。MyResourceWrapper 会覆写 virtual Dispose(bool disposing) 方法,并提供已建立 Managed 和 Unmanaged 资源的清除程式码。MyResourceWrapper 也会在它自己的基底类别 BaseResource 上呼叫 Dispose,以确保可以正常清除其所使用的基底。请注意,衍生类别 (Derived Class) MyResourceWrapper 并没有不含参数的 Finalize 方法或是 Dispose 方法,因为它会从基底类别 BaseResource 继承。

注意   此一范例中的 protected Dispose(bool disposing) 方法并不会强制使用执行绪安全,这是因为您无法同时从使用者执行绪和完成项执行绪呼叫该方法。此外,使用 BaseResource 的用户端应用程式还应该永远不让多个使用者执行绪同时呼叫 protected Dispose(bool disposing) 方法。应用程式或类别库 (Class Library) 应该设计成只能让一个执行绪拥有资源的存留期,并且要在不复需要资源时才呼叫 Dispose。视资源而定,未同步化的执行绪存取在处置资源时可能会造成安全性的风险。开发人员应该小心检视其程式码,并据以判断强制使用执行绪安全的最佳方式。

<SPAN class=”lang”>[Visual Basic]
</SPAN>’ Design pattern for the base class.
‘ By implementing IDisposable, you are announcing that instances
‘ of this type allocate scarce resources.
Public Class BaseResource
   Implements IDisposable
   ’ Pointer to an external unmanaged resource.
   Private handle As IntPtr 
   ’ Other managed resource this class uses.
   Private Components As Component
   ’ Track whether Dispose has been called.
   Private disposed As Boolean = False

   ’ Constructor for the BaseResource Object.
   Public Sub New()
      ’ Insert appropriate constructor code here.
   End Sub

   ’ Implement IDisposable.
   ’ Do not make this method Overridable.
   ’ A derived class should not be able to override this method.
   Public Overloads Sub Dispose()Implements IDisposable.Dispose
      Dispose(true)
      ’ Take yourself off of the finalization queue
      ’ to prevent finalization code for this object
      ’ from executing a second time.
      GC.SuppressFinalize(Me) 
   End Sub

‘ Dispose(disposing As Boolean) executes in two distinct scenarios.
‘ If disposing is true, the method has been called directly 
‘ or indirectly by a user’s code. Managed and unmanaged resources 
‘ can be disposed.
‘ If disposing equals false, the method has been called by the runtime
‘ from inside the finalizer and you should not reference other    
‘ objects. Only unmanaged resources can be disposed.
Protected Overloads Overridable Sub Dispose(disposing As Boolean)
   ’ Check to see if Dispose has already been called.
   If Not (Me.disposed) Then
      ’ If disposing equals true, dispose all managed 
      ’ and unmanaged resources.
      If (disposing) Then
         ’ Dispose managed resources.
         Components.Dispose()
      End If
      ’ Release unmanaged resources. If disposing is false,
      ’ only the following code is executed.      
      CloseHandle(handle)
      handle = IntPtr.Zero
      ’ Note that this is not thread safe.
      ’ Another thread could start disposing the object
      ’ after the managed resources are disposed,
      ’ but before the disposed flag is set to true.
      ’ If thread safety is necessary, it must be
      ’ implemented by the client.
   End If
   Me.disposed = true
End Sub

   ’ This Finalize method will run only if the 
   ’ Dispose method does not get called.
   ’ By default, methods are NotOverridable. 
   ’ This prevents a derived class from overriding this method.
   Protected Overrides Sub Finalize()
         ’ Do not re-create Dispose clean-up code here.
         ’ Calling Dispose(false) is optimal in terms of
         ’ readability and maintainability.
         Dispose(false)
   End Sub
   
   ’ Allow your Dispose method to be called multiple times,
   ’ but throw an exception if the object has been disposed.
   ’ Whenever you do something with this class, 
   ’ check to see if it has been disposed.
   Public Sub DoSomething()
      If Me.disposed Then
         Throw New ObjectDisposedException()
      End if
   End Sub
End Class

‘ Design pattern for a derived class.
‘ Note that this derived class inherently implements the 
‘ IDisposable interface because it is implemented in the base class.
Public Class MyResourceWrapper
   Inherits BaseResource
   
   ’ A managed resource that you add in this derived class.
   private addedManaged As ManagedResource
   ’ A native unmanaged resource that you add in this derived class.
   private addedNative As NativeResource
   ’ Track whether Dispose has been called.
   Private disposed As Boolean = False

   ’ Constructor for the MyResourceWrapper object.
   Public Sub New()      
      MyBase.New()
      ’ Insert appropriate constructor code here for the
  &

nbsp;   ’ added resources.
   End Sub

   Protected Overloads Overrides Sub Dispose(disposing As Boolean)
      If Not (Me.disposed) Then
         Try
            If disposing Then
              ’ Release the managed resources you added in
              ’ this derived class here.
              addedManaged.Dispose()
            End If
            ’ Release the native unmanaged resources you added
            ’ in this derived class here.
            CloseHandle(addedNative)
            Me.disposed = true
         Finally
            ’ Call Dispose on your base class.
            MyBase.Dispose(disposing)
         End Try
      End If
   End Sub
End Class
‘ This derived class does not have a Finalize method
‘ or a Dispose method without parameters because it 
‘ inherits them from the base class.

<SPAN class=”lang”>[C#]</SPAN>
// Design pattern for the base class.
// By implementing IDisposable, you are announcing that instances
// of this type allocate scarce resources.
public class BaseResource: IDisposable
{
   // Pointer to an external unmanaged resource.
   private IntPtr handle;
   // Other managed resource this class uses.
   private Component Components;
   // Track whether Dispose has been called.
   private bool disposed = false;

   // Constructor for the BaseResource object.
   public BaseResource()
   {
      // Insert appropriate constructor code here.
   }

   // Implement IDisposable.
   // Do not make this method virtual.
   // A derived class should not be able to override this method.
   public void Dispose()
   {
      Dispose(true);
      // Take yourself off the Finalization queue 
      // to prevent finalization code for this object
      // from executing a second time.
      GC.SuppressFinalize(this);
   }

   // Dispose(bool disposing) executes in two distinct scenarios.
   // If disposing equals true, the method has been called directly
   // or indirectly by a user’s code. Managed and unmanaged resources
   // can be disposed.
   // If disposing equals false, the method has been called by the 
   // runtime from inside the finalizer and you should not reference 
   // other objects. Only unmanaged resources can be disposed.
   protected virtual void Dispose(bool disposing)
   {
      // Check to see if Dispose has already been called.
      if(!this.disposed)
      {
         // If disposing equals true, dispose all managed 
         // and unmanaged resources.
         if(disposing)
         {
            // Dispose managed resources.
            Components.Dispose();
         }
         // Release unmanaged resources. If disposing is false, 
         // only the following code is executed.
         CloseHandle(handle);
         handle = IntPtr.Zero;
         // Note that this is not thread safe.
         // Another thread could start disposing the object
         // after the managed resources are disposed,
         // but before the disposed flag is set to true.
         // If thread safety is necessary, it must be
         // implemented by the client.

      }
      disposed = true;         
   }

   // Use C# destructor syntax for finalization code.
   // This destructor will run only if the Dispose method 
   // does not get called.
   // It gives your base class the opportunity to finalize.
   // Do not provide destructors in types d

erived from this class.
   ~BaseResource()      
   {
      // Do not re-create Dispose clean-up code here.
      // Calling Dispose(false) is optimal in terms of
      // readability and maintainability.
      Dispose(false);
   }

   // Allow your Dispose method to be called multiple times,
   // but throw an exception if the object has been disposed.
   // Whenever you do something with this class, 
   // check to see if it has been disposed.
   public void DoSomething()
   {
      if(this.disposed)
      {
         throw new ObjectDisposedException();
      }
   }
}

// Design pattern for a derived class.
// Note that this derived class inherently implements the 
// IDisposable interface because it is implemented in the base class.
public class MyResourceWrapper: BaseResource
{
   // A managed resource that you add in this derived class.
   private ManagedResource addedManaged;
   // A native unmanaged resource that you add in this derived class.
   private NativeResource addedNative;
   private bool disposed = false;

  // Constructor for this object.
   public MyResourceWrapper()
   {
      // Insert appropriate constructor code here.
   }

   protected override void Dispose(bool disposing)
   {
      if(!this.disposed)
      {
         try
         {
            if(disposing)
            {
               // Release the managed resources you added in
               // this derived class here.
               addedManaged.Dispose();         
            }
            // Release the native unmanaged resources you added
            // in this derived class here.
            CloseHandle(addedNative);
            this.disposed = true;
         }
         finally
         {
            // Call Dispose on your base class.
            base.Dispose(disposing);
         }
      }
   }
}

// This derived class does not have a Finalize method
// or a Dispose method without parameters because it inherits 
// them from the base class.

实作 Close 方法

对於呼叫 Close 方法比呼叫 Dispose 方法来得更自然的型别,请将公用 Close 方法加入至基底型别中。Close 方法会接着呼叫不含参数的 Dispose 方法,以执行正确的清除作业。下列程式码范例是在说明 Close 方法。

<SPAN class=”lang”>[Visual Basic]
</SPAN>’ Do not make this method Overridable.
‘ A derived class should not be allowed
‘ to override this method.
Public Sub Close()
   ’ Calls the Dispose method without parameters.
   Dispose()
End Sub

<SPAN class=”lang”>[C#]</SPAN>
// Do not make this method virtual.
// A derived class should not be allowed
// to override this method.
public void Close()
{
   // Calls the Dispose method without parameters.
   Dispose();
}

请参阅

GC.SuppressFinalize 方法 | 使用 C# 和 Managed Extensions for C++ 解构函式语法 | 覆写 Finalize 方法

转载自:http://msdn.microsoft.com/library/cht/default.asp?url=/library/CHT/cpguide/html/cpconimplementingdisposemethod.asp

Share
Posted in 编程 | Leave a comment

转载:类别、元件和控制项的比较

这个主题将定义元件和控制项;这里的讨论应可协助您决定何时应实作元件或控制项的类别。

下列清单为实作器提供了较松的方针。

  • 如果您的类别使用外部资源,但是不会用在设计介面上,请实作 System.IDisposable,或是从直接或间接实作 IDisposable 的类别衍生。
  • 如果您的类别会用在设计介面上 (例如 Windows Form 或 Web Form 设计工具),请实作 System.ComponentModel.IComponent,或是从直接或间接实作 IComponent 的类别衍生。请注意,IComponent 会扩充 IDisposable,因此 IComponent 型别一定是 IDisposable 型别。IComponent 型别在效能上的负荷比非 IComponentIDisposable 型别要小,但是这通常会被在设计阶段和 Run Time 时设置 IComponent 的能力抵销 (设置会在这个主题稍後加以说明)。
  • 如果您希望类别是可设计的 (用在设计介面上),而且可用传址 (By Reference) 方式封送处理,您可以从 System.ComponentModel.Component 衍生。Component 是用传址方式封送处理的 IComponent 型别的基底实作。
  • 如果您希望可设计的类别是用传值 (By Value) 方式封送处理,您可以从 System.ComponentModel.MarshalByValueComponent 衍生。MarshalByValueComponent 是用传值方式封送处理的 IComponent 型别的基底实作。
  • 如果您想在您的物件模型阶层架构中引入 IComponent 型别 (而且由於单一继承 (Inheritance) 的关系而无法从 ComponentMarshalByValueComponent 这类基底实作衍生),请实作 IComponent
  • 如果您希望可设计的类别提供使用者介面,您的类别就是控制项。控制项必须直接或间接从其中一个基底控制项类别衍生 – System.Windows.Forms.ControlSystem.Web.UI.Control

    注意   如果类别不可设计,也没有保留外部资源,您就不需要 IComponentIDisposable 型别。

接着说明的是元件、控制项、容器 (Container) 和网站的定义。

元件

在 .NET Framework,元件是指实作 System.ComponentModel.IComponent 介面的类别,或者从实作 IComponent 之类别直接或间接衍生的类别。在程式设计中,元件一词通常是使用於可以重复使用而且可以与其他物件互动的物件。.NET Framework 元件不仅满足这些一般性的要求,并且还额外地提供一些功能,例如对外部资源的控制以及设计阶段支援。

对外部资源的控制

IComponent 介面扩充 System.IDisposable 介面,在後者的约定中有一个名为 Dispose 的方法。在它的 Dispose 方法实作 (Implementation) 中,元件必须明确地释放外部资源。这样就提供一种释放资源的决定性方式,不同於透过记忆体清除发生的预设非决定性清除。开发者必须传播 Dispose 到整个 Containment 阶层架构,以确保元件的子系也会释放资源。此外,衍生的元件必须叫用其基底类别 (Base Class) 的 Dispose 方法。

注意   即使透过 Dispose 提供对资源的明确控制,您仍然应该透过完成项 (解构函式) 提供隐含的清除,以防止使用者万一没有对您元件呼叫 Dispose 时,造成资源的永久性遗漏。

下列范例所示是在基底元件和衍生元件中实作 Dispose 的模式。

[C#]
public class BaseComponent : IComponent {

   // IComponent extends IDisposable.
   public void Dispose() {
        Dispose(true);
     GC.SuppressFinalize(this);
      }

   protected virtual void Dispose(bool disposing) {
      if (disposing) {
          // Free other state (managed objects).
      }
      // Free your own state (unmanaged objects).
   }

   // Simply call Dispose(false).
      ~BaseComponent(){
      Dispose (false);
   }
}

// Derived component.
public class DerivedComponent : BaseComponent {

   protected override void Dispose(bool disposing) {
      if (disposing) {
      // Free other state.
      }
      // You must invoke the Dispose method of the base class.
      base.Dispose(disposing);
      // Free your own state.
      ...
   }
   // No finalizer/destructor.
   // No Dispose() method.
}

[Visual Basic]
' Design pattern for a base class.
Public Class BaseComponent
   Implements IComponent
   ' Implement IDisposable
   Public Overloads Sub Dispose()
      Dispose(True)
      GC.SuppressFinalize(Me)
   End Sub

   Protected Overloads Overridable Sub Dispose(disposing As Boolean)
      If disposing Then
         ' Free other state (managed objects).
      End If
      ' Free your own state (unmanaged objects).
      ' Set large fields to null.
   End Sub

   Protected Overrides Sub Finalize()
      ' Simply call Dispose(False).
      Dispose (False)
   End Sub
End Class

' Design pattern for a derived component.
Public Class DerivedComponent
   Inherits BaseComponent

   Protected Overloads Overrides Sub Dispose(disposing As Boolean)
      If disposing Then
         ' Release managed resources.
      End If
      ' Release unmanaged resources.
      ' Set large fields to null.
      ' Call Dispose on your base class.
      Mybase.Dispose(disposing)
   End Sub
   ' The derived class does not have a Finalize method
   ' or a Dispose method with parameters because it inherits
   ' them from the base class.
End Class

设计阶段支援

.NET Framework 中的元件有一个重要功能,那就是它们是可设计的,这表示身为元件的类别可用於快速应用程式开发 (RAD) 环境中,例如 Visual Studio .NET。您可以将元件加入至 Visual Studio .NET 的工具箱、可将其拖放到表单上,也可以在设计介面上进行处理。请注意,IComponent 型别的基底设计阶段支援是内建於 .NET Framework;元件开发人员不必执行额外的工作,就可以使用基底设计阶段的功能。

如需设计阶段支援的详细资讯,请参阅元件的设计阶段属性增强设计阶段支援

装载元件

元件可以设置 (装载) 於容器 (Container) 之内 (本主题稍後会予定义)。当元件被设置时,它是透过它的站台 (本主题稍後会予定义) 与容器互动,并且能够透过站台从它的容器查询和取得服务。为确保容器被拆除时资源会被释放,容器必须实作 IDisposable 介面。容器在它的 Dispose 方法实作中,必须释放它所持有的所有资源,并且叫用它所包含每一个元件的 Dispose 方法。

Containment 是逻辑性的,不需要具有视觉化的表示方式。设置资料库元件的中介层 (Middle Tier) 容器就是非视觉化 Containment 的范例。视觉化的 Containment 会在 Visual Studio .NET 的 Windows Form 设计工具和 Web Form 设计工具中看见。视觉化的设计介面是一个容器,可装载表单元件 (在 Web Form 中是 Page 元件)。

封送处理元件

元件可分为可远端处理者及不可远端处理者。可远端处理的元件是以传址 (By Reference) 或传值 (By Value) 方式封送处理。封送处理包括跨界限传送物件,所谓界限包括应用程式定义域 (轻量处理序)、处理序和电脑。当物件以传址方式封送处理时,会建立对该物件进行远端呼叫的 Proxy。当物件以传值方式封送处理时,会跨相关界限传送物件的序列化复本。

封装系统资源、大型或以单一执行个体 (Instance) 存在的可远端处理元件应该以传址方式封送处理。以传址方式封送处理之元件的基底类别为 System.ComponentModel.Component。这个基底类别会实作 IComponent 并且是从 MarshalByRefObject 衍生。.NET Framework 类别库 (Class Library) 中的许多元件都是从 Component 衍生而来,包括 System.Windows.Forms.Control (Windows Form 控制项的基底类别)、System.Web.Services.WebService (使用 ASP.NET 所建立的 XML Web Service 的基底类别) 和 System.Timers.Timer (产生递回事件的类别)。

只存有状态的可远端处理元件应该以传值方式封送处理。以传值方式封送处理之元件的基底类别为 System.ComponentModel.MarshalByValueComponent。这个基底类别会实作 IComponent 并且是从 Object 衍生。.NET Framework 类别库中只有少数几个元件是从 MarshalByValueComponent 衍生。所有这类元件都在 System.Data 命名空间 (Namespace) 之内 (DataColumnDataSetDataTableDataViewDataViewManager)。

注意   以传值和传址方式封送处理之物件的基底类别分别为 ObjectMarshalByRefObject,但是对应的衍生类别 (Derived Class) 则命名为 MarshalByValueComponentComponent。这种命名配置所依据的逻辑是,越常使用的型别要具有越简单的名称。

如果元件不需要远端处理,就不要从基底实作衍生 Component,而是直接实作 IComponent

如需物件远端处理的详细资讯,请参阅 .NET 远端处理概观

控制项

控制项是一种提供 (或启用) 使用者介面 (UI) 能力的元件。.NET Framework 为控制项提供了两个基底类别:一个是用户端 Windows Form 控制项,另一个是 ASP.NET 伺服器控制项。它们是 System.Windows.Forms.ControlSystem.Web.UI.Control。.NET Framework 类别库中的所有控制项都是从这两个类别直接或间接衍生。System.Windows.Forms.Control 是从 Component 衍生,而且它本身提供 UI 能力。System.Web.UI.Control 会实作 IComponent,而且会提供很容易在上面加入 UI 功能的基础结构。

注意   每个控制项都是一个元件,但每个元件不一定是控制项。

容器和站台

如果您要开发 Windows Form 或 Web Form 网页 (ASP.NET 网页) 的元件和控制项,您不需实作容器或站台。Windows Form 和 Web Form 的设计工具,就相当於Windows Form 和 ASP.NET 伺服器控制项的容器。容器可对设置於它们之内的元件和控制项提供服务。在设计阶段,控制项是设置在设计工具中,并且从设计工具取得服务。为完整起见,仅将容器和站台的定义列述如下。

容器
容器是实作 System.ComponentModel.IContainer 介面的类别,或者从实作这个介面之类别衍生的类别。容器在逻辑上可包含一个或多个被称为容器子元件的元件。
网站
站台是实作 System.ComponentModel.ISite 介面的类别,或者从实作这个介面之类别衍生的类别。站台是由容器提供,用来管理其子元件并且与它们通讯。通常,一个容器和一个站台会实作为一个单元。

请参阅

属性概观 | 元件的设计阶段属性 | 开发 Windows Form 控制项 | 开发 ASP.NET 伺服器控制项 | 增强设计阶段支援

转载自:http://msdn.microsoft.com/library/cht/default.asp?url=/library/CHT/cpguide/html/cpconclassvscomponentvscontrol.asp

Share
Posted in 编程 | Leave a comment