您的位置:首页 > 编程语言 > C#

c#实现软件注册

2014-11-26 16:20 197 查看
http://www.cnblogs.com/ynbt/archive/2011/11/02/2233470.html

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace SoftRegister
{
public partial class frmMainForm : Form
{
public frmMainForm()
{
InitializeComponent();
}
SoftReg softReg = new SoftReg();
private void btnClose_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void btnReg_Click(object sender, EventArgs e)
{
frmRegisterForm frmRegister = new frmRegisterForm();
frmRegister.ShowDialog();
}

///<summary>
/// 窗体加载
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
private void frmMainForm_Load(object sender, EventArgs e)
{
//判断软件是否注册
RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("wxf").CreateSubKey("wxf.INI");
foreach (string strRNum in retkey.GetSubKeyNames())
{
if (strRNum == softReg.GetRNum())
{
this.lblRegInfo.Text = "此软件已注册!";
this.btnReg.Enabled = false;
return;
}
}
this.Text = "此软件尚未注册!";
this.btnReg.Enabled = true;
MessageBox.Show("您现在使用的是试用版,可以免费试用30次!","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
Int32 tLong;
try
{
tLong= (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Angel", "UseTimes", 0);
MessageBox.Show("您已经使用了" + tLong + "次!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("欢迎使用本软件!","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Angel","UseTimes",0,RegistryValueKind.DWord);
}
tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Angel", "UseTimes", 0);
if (tLong < 30)
{
int tTimes = tLong + 1;
Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Angel", "UseTimes", tTimes);
}
else
{
DialogResult result = MessageBox.Show("试用次数已到!您是否需要注册?", "信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
frmRegisterForm.state = false;
btnReg_Click(sender, e);
}
else
{
Application.Exit();
}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: