Hi,
Try below code:
using System;
using System.Windows.Forms;
namespace SerialNumberReset
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
tbSerialNumber.Text = GetSerialNumber().ToString();
}
private int GetSerialNumber()
{
if (DateTime.Now.Date > Properties.Settings.Default.ReferenceDate.Date)
{
Properties.Settings.Default.ReferenceDate = DateTime.Now;
return 1;
}
else
{
return Properties.Settings.Default.SerialNumber;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Save();
}
private void buttonUpdateSerialNumber_Click(object sender, EventArgs e)
{
Properties.Settings.Default.SerialNumber = GetSerialNumber() + 1;
tbSerialNumber.Text = Properties.Settings.Default.SerialNumber.ToString();
}
}
}