ImonBayazid
ImonBayazid

Reputation: 1096

Running a form for only once in entire Windows form application lifetime

In my project i want to show a user-guide when the user first installs my software.So, for only one time i want to show (at beginning) a window where some direction is given so that a user can understand in first time how to use my software.After the user once watches the window(user guide) this window will not appear further time. I want to use a form like userguid.cs. this will show in the begging of the mainwindow for one time in the life of the my application. N:B: For example if user restart his computer and again run the app it will not show the userguide window again as it shows before How can i do that?? Can anyone give idea how can i do that???

Upvotes: 2

Views: 1825

Answers (2)

Kareem Khan
Kareem Khan

Reputation: 56

Simply maintain a flag, which will help you store, whether the user guide has been displayed or not.

The flag can be a file, which is stored in your application directory, or if you have a database, you can store the boolean value in a db.

Then call the function to display the user guide, when the form loads, or wherever you require.

public void Form1_Load() {
   displayUserGuide();
}

And, in the function displayUserGuide see whether flag has been set or not.

public void displayUserGuide() {
  //Return, if the form has already been displayed.
  if(File.Exists("UGUID")) return;
  userGuide.Show();
  File.Create("UGUID");
}

You can simply call the functiondisplayUserGuide() any where you want throughout the Application. The function will make sure the form is displayed only once.

In this way you can display Windows form application once.

Hope this helps!

Upvotes: 1

Rajesh Subramanian
Rajesh Subramanian

Reputation: 6490

You can create a dummy file in the application path to make sure whether userguide displayed or not.

For Example,

Before loading UserGuide.cs, check for the following,

if(!File.Exists("UserGuideShown"))
{

  UserGuide.Show();
  File.Create("UserGuideShown");
}

When next time, the application loads, it will check for the file, it will be exists as it shown already. so it will skip showing up..

Upvotes: 0

Related Questions