14. August 2013 21:32
The Entry point method of C# Winform application looks as below.
static void Main()
Here [STAThread] attribute decoration is essential to mark your application state as single threaded apartment style.For details read my article What STAThread Attribute does?
In this article today I explain about the need of Application.EnableVisualStyles() method.If you comment this line Application.EnableVisualStyles() and run the application you will see all the controls in your form rendered with the classic Windows look only.
If you uncomment Application.EnableVisualStyles() and run the application you can see all your controls rendered with current operating system theme settings. Means, If your operating system is Windows it will use the built-in Windows theming to style controls and classic Windows look and feel if EnableVisualStyle() is commented.
So it is not a method which if commented will cause the application to crash or stop working. It is essential to apply the visual styles like colors, fonts, and other visual elements to your form controls from the current operating system theme. If the control and the operating system support this controls will draw with visual styles if this method is used.
Also Application.EnableVisualStyles() method must be called as first line in Main method before calling any controls in the application to have the effect.