C#授权组件设计 - LicenseControlProject

来源:互联网 发布:qq空间剪影软件 编辑:程序博客网 时间:2024/05/22 17:29

授权组件设计 - LicenseControlProject

 

授权组件设计使用到的主要类型 - System.ComponentModel.License  
核心代码:   (点击此处下载源代码

  1. public class LicenseControl
  2. {
  3.     private License license = null;
  4.     public LicenseControl()
  5.     {
  6.           license = LicenseManager.Validate(typeof(LicenseControl), this);         
  7.           InitializeComponent();
  8.     }
  9.     protected override void Dispose(bool disposing)
  10.     {
  11.         //释放资源
  12.         if (disposing && (license != null))
  13.         {
  14.           license.Dispose();
  15.           license = null;
  16.         }
  17.         if (disposing && (components != null))
  18.         {
  19.           components.Dispose();
  20.         }
  21.         base.Dispose(disposing);
  22.     }
  23. }

一、以下是组件主要代码:

  1.  using System;
  2.  using System.Collections.Generic;
  3.  using System.ComponentModel;
  4.  using System.Drawing;
  5.  using System.Data;
  6.  using System.Text;
  7.  using System.Windows.Forms;
  8.  namespace LicenseControlProject
  9. {
  10.     public partial class LicenseControl : UserControl
  11.     {
  12.         private License license = null;
  13.         public LicenseControl()
  14.         {
  15.             license = LicenseManager.Validate(typeof(LicenseControl), this);
  16.             InitializeComponent();
  17.         }
  18.         /**//// <summary>
  19.         /// 清理所有正在使用的资源。
  20.         /// </summary>
  21.         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
  22.         protected override void Dispose(bool disposing)
  23.         {
  24.             //释放资源
  25.             if (disposing && (license != null))
  26.             {
  27.                 license.Dispose();
  28.                 license = null;
  29.             }
  30.             if (disposing && (components != null))
  31.             {
  32.                 components.Dispose();
  33.             }
  34.             base.Dispose(disposing);
  35.         }
  36.     }
  37. }

二、用户使用本组件时需获得一个NameSpace.Class.LIC授权文件。
  文件格式:"NameSpace.Class 是一个授权组件。"
  例如:"LicenseControlProject.LicenseControl 是一个授权组件。"

源文:http://www.cnblogs.com/CrackerLeader/articles/517547.html