TechyMedia

A .NET Technology blog | .NET,C# Progamming,C# tutorials,WPF WCF|Software Engineer

NAVIGATION - SEARCH

What is the use of Application.EnableVisualStyles()?

Application.EnableVisualStyles() 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.
The Entry point method of C#  Winform application looks as below.
 
[STAThread]
static void Main()
{
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
}
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. 

The Innovators: How a Group of Inventors, Hackers, Geniuses and Geeks Created the Digital Revolution- A must Read

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.
 

What is Application.SetCompatibleTextRenderingDefault(false)?

 

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading