-2

使用 10 次后如何关闭 Windows 窗体应用程序作为试用版?此表单不需要任何登录或注册。就在我运行程序并关闭它时,使用了 10 次后,出现一个 MessageBox 说 The form is Trial。

4

1 回答 1

2

这是您可以使用的示例。添加名为 LoadCount 的应用程序设置并将范围设置为用户。现在这里是如何处理负载计数的代码:

    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);
        }
    }

请注意,默认情况下此设置不受保护。

于 2012-09-29T19:28:16.373 回答