如何在使用10次后关闭Windows窗体应用程序作为试用版? 此表单不需要任何登录或注册。 就在我运行程序并关闭它之后,使用了10次,一个MessageBox 似乎说该表格是试用。
答案 0 :(得分:2)
以下是您可以使用的示例。添加名为LoadCount的应用程序设置并将范围设置为user。现在这里是代码如何处理负载计数:
private void Form1_Load(object sender, EventArgs e)
{
//check load count...
int loadCount = ApplicationSettingsDemo.Properties.Settings.Default.LoadCount;
if (loadCount > 10)
{
MessageBox.Show("Trial version expired!");
this.Close();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
ApplicationSettingsDemo.Properties.Settings.Default.LoadCount += 1;
ApplicationSettingsDemo.Properties.Settings.Default.Save();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,
"Failed to save settings",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
请注意,默认情况下,此设置不受保护。