0

So in my program.cs file, this default code works perfectly:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault (false);
Application.Run (new frmClarity());

However, if I try to add a using statement, EnableVisualStyles() doesn't seem to execute anymore! No errors, it just doesn't style the forms. Both of these attempts have the effect of visual styles not executing:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault (false);

    using (new Impersonator.Impersonator (
    
       ConfigurationManager.AppSettings ["login"], ConfigurationManager.AppSettings ["domain"], 
       ConfigurationManager.AppSettings ["password"])) {
    
       Application.Run (new frmClarity());
    }
}

OR

using (new Impersonator.Impersonator (

   ConfigurationManager.AppSettings ["login"], ConfigurationManager.AppSettings ["domain"], 
   ConfigurationManager.AppSettings ["password"])) {

   Application.EnableVisualStyles();
   Application.SetCompatibleTextRenderingDefault (false);

   Application.Run (new frmClarity());
}
}

Does anyone know why adding a USING statement in program.cs causes this weird behavior?

John
  • 185
  • 1
  • 3
  • 17
  • It must execute before *any* windows are created. We can't see what Impersonator does, the syntax error doesn't exactly help. There is no good reason to delay it. – Hans Passant Aug 19 '20 at 19:55
  • No windows are created by Impersonator. It just changes the account that the app is running under. Sorry for the syntax error--I put the extra brace in above. There are no syntax errors in my executing code). In my first "not working" example, EnableVisualStyles() is the very first thing that executes. – John Aug 19 '20 at 20:02

0 Answers0