c# - When form load, open form 2 and close form 1 -


when program loads want check file, if file exists want continue, if doesn't want not open main form , open form 2.

this have far:

private void home_load(object sender, eventargs e) {     string path = @"c:\path\path2\file.txt";     if (!file.exists(path))     {         messagebox.show("file not found!");         form2 f = new form2();         f.show();         this.hide();     }      else     {         messagebox.show("file found!");     } } 

but opens 2 forms. can please me? thanks.

seems me should in application start. right you're doing in load of first form, don't want open. so, this:

[stathread] static void main() {     application.enablevisualstyles();     application.setcompatibletextrenderingdefault(false);     string path = @"c:\path\path2\file.txt";     if (!file.exists(path))     {         application.run(new form2());     }     else     {         application.run(new form1());     } } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -