授权组件设计 - LicenseControlProject
授权组件设计使用到的主要类型 - System.ComponentModel.License
核心代码: (点击此处下载源代码)
- public class LicenseControl
- {
- private License license = null;
- public LicenseControl()
- {
- license = LicenseManager.Validate(typeof(LicenseControl), this);
- InitializeComponent();
- }
- protected override void Dispose(bool disposing)
- {
- //释放资源
- if (disposing && (license != null))
- {
- license.Dispose();
- license = null;
- }
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- }
一、以下是组件主要代码:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- namespace LicenseControlProject
- {
- public partial class LicenseControl : UserControl
- {
- private License license = null;
- public LicenseControl()
- {
- license = LicenseManager.Validate(typeof(LicenseControl), this);
- InitializeComponent();
- }
- /**//// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
- protected override void Dispose(bool disposing)
- {
- //释放资源
- if (disposing && (license != null))
- {
- license.Dispose();
- license = null;
- }
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
二、用户使用本组件时需获得一个NameSpace.Class.LIC授权文件。
文件格式:"NameSpace.Class 是一个授权组件。"
例如:"LicenseControlProject.LicenseControl 是一个授权组件。"
源文:http://www.cnblogs.com/CrackerLeader/articles/517547.html