954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Opening for the first time

Ok, I have a code that I only want to use for the first form1 load, so that means never use it agian.

So how do I use a code once then never use it again?

GAME
Junior Poster
166 posts since Mar 2010
Reputation Points: 5
Solved Threads: 1
 

Do you mean never use it again while the application is running? Or never use it when the application is run in the future?

If it is the latter, you could add a bool flag to your projects Properties Settings.settings which is initialised to false. Upon entering form1_Load for the first time, the flag would be checked to ensure it is false, allowing the code to execute. The flag is then updated inhibiting it from the code being executed in the future.

Cameron

CanYouHandstand
Light Poster
27 posts since Nov 2009
Reputation Points: 10
Solved Threads: 2
 

Declare a Boolean static field.

public class Form1 : ....
 {
    static bool flag=true;

    void form1_load(...) {
           if(flag) {
                  ....
                  flag=false;
           }
    }
 }
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: