Windows Forms application - visual style?

I will try to make it as simple as possible.

The button created in the Windows Forms application is as follows:

enter image description here

If I create the form manually, the buttons that I create will look like this:

enter image description here

I carefully studied the Windows Forms application and did not find any code that changes the display style of the buttons.

Are there any simple explanations why this is happening?

Thanks in advance.

+7
source share
4 answers

You will need to call the EnableVisualStyles method, which by default is called in the Main method of the Program class before calling Application.Run (when creating a Windows Forms project with automatically generated code).

This method allows you to create visual styles for the application. The visual style is the colors, fonts, and other visual elements that make up the theme of the operating system. The controls will draw using visual styles if the control and the operating system support it. To have an effect, EnableVisualStyles() must be called before creating any controls in the application; usually EnableVisualStyles() is the first line in the main function. A separate manifest is not required to enable visual styles when calling EnableVisualStyles() .

+11
source

Make sure you set the UseVisualStyleBackColor buttons to true and you call Application.EnableVisualStyles(); in your starter code.

 static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmAddress()); } } 

EDIT: Effect of using VisualStyleBackColor:

enter image description here

+2
source

Even if you have enabled visual styles (by default), part of the display of the button is controlled by the operating system, outside the control of your program. The same program, working in Windows 7 with a standard interface, will look different than when working in classic mode.

A bold accent is added to the excerpt from the document to illustrate this point.

http://msdn.microsoft.com/en-us/library/y6kzhf8d(VS.80).aspx

Windows XP introduced a new Windows user interface with controls that have rounded corners and that change color when you pause the mouse over them. By default, Windows-based applications created using Visual Basic automatically support styles, also known as Windows XP Themes. When launched on a platform that does not support Windows XP themes, the application reverts to the traditional look of Windows. If you do not want your application to support visual styles, you can change the property on the Project application page.

Also here: http://msdn.microsoft.com/en-us/library/ms171733(VS.80).aspx

See Verifying visual style support .

for visual styles, the following conditions must be met:

  • The operating system supports visual styles.
  • The user has activated visual styles in the operating system.
  • Visual styles are included in the app.
  • Visual styles are used to draw the client area of ​​application windows.
+1
source

I had a similar problem. Until early 2010, creating a custom manifest file did the job. However, this does not work from Visual Studio 2010 because VS creates a new file called app.manifest inside the My Project folder. So, to enable visual styles, you just need to edit this file using your project in Visual Studio and uncomment the lines below.

 <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) --> 
0
source

All Articles