I've built a little WindowsForm app from a standard beginner's tutorial. The kind where you use controls like buttons and textboxes to add 2 numbers and have the result show up in a textbox.
Anyways, I want to make it so that when a user clicks on my .exe, it checks against my built-in expiration date before even launching the program/window. That is, if my expiration date were today Oct. 30, nothing happens, no window form even shows up. However, if my expiration date were to be Oct. 31, everything proceeds normally and windows and forms show up. But, tomorrow on Oct. 31 (expiration date) and any day after tomorrow if the user were to run my .exe, nothing would happen.
I think my code would look something like this:
DateTime expiration = new DateTime(2013, 10, 31) //Oct. 31, 2013
If (DateTime.Today < expiration) //proceed normally
else // do nothing, nothing happens for the user
From the tutorial, most of my understanding is confined to code written inside the public Form1 : Form part of the code:
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
Where would I insert code to check today's date against my expiration date so that no forms are loaded?
Look at Program.cs in your Solution Explorer. You can add this code inside the Main function, and call Application.Exit() to leave the application if the condition you have specified hasn't been met.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With