標籤:blog http io ar os 使用 sp for on
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();
}
}
}
}
}
c#實現軟體註冊