Reputation:
When a user runs the program for the first time I want a message box to show up.
I was thinking of something like this:
private void Form1_Load(object sender, EventArgs e)
{
if(firstTime)
{
MessageBox.Show("Welcome");
}
How could I get my program to display a message box when a user launches the program for the first time in c#?
Upvotes: 1
Views: 103
Reputation:
You can add a parameter to the application settings.
Go to the solution explorer in the section Properties
and double click on Settings.settings
.
Add a parameter named for example IsFirstLaunch
and set type to bool with value True
.
Then you can write:
if ( Properties.Settings.Default.IsFirstLaunch )
{
Properties.Settings.Default.IsFirstLaunch = false;
Properties.Settings.Default.Save();
MessageBox.Show("Welcome");
}
The settings are stored in:
c:\Users\{UserName}\AppData\Local\{Assembly CompanyName}\{Assembly Name}.Url__________
So be careful to set Assembly CompanyName
in the AssemblyInfo.cs
in the same section.
Assembly Name
is from the application project properties (double click on this Properties
section).
You can delete this file to test again.
Upvotes: 1
Reputation: 3880
You would need to store that information somewhere
Then read the value, and setup the firstTime flag prior to check.
Upvotes: 2