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>
Form loading
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
private void Frmmainform_load (object sender, EventArgs e)
{
Determine if the software is registered
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 software is registered!" ";
this.btnReg.Enabled = false;
Return
}
}
This. Text = "This software has not been registered!" ";
This.btnReg.Enabled = true;
MessageBox.Show ("You are now using a trial version, you can try it for free 30 times!") "," Information ", messageboxbuttons.ok,messageboxicon.information);
Int32 Tlong;
Try
{
Tlong= (Int32) registry.getvalue ("Hkey_local_machine\\software\\angel", "Usetimes", 0);
MessageBox.Show ("You have used the" + Tlong + "times!) "," Information ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Catch
{
MessageBox.Show ("Welcome to use the software!") "," Information ", 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 ("The number of trials has arrived!") Do you need to register? "," Information ", Messageboxbuttons.yesno, MessageBoxIcon.Information);
if (result = = Dialogresult.yes)
{
Frmregisterform.state = false;
Btnreg_click (sender, E);
}
Else
{
Application.exit ();
}
}
}
}
}
C # Implementing Software Registration