I'll try to keep this as simple as possible.
A button created in a Windows Forms Application looks like this:
If I create a form manually, buttons I create will look like this:
I looked thoroughly through the Windows Forms Application and found no code that changes the visual style of buttons.
Is there any simple explanation as to why this is happening?
Thanks in advance.
WinForms is based on the user32/GDI technology that has existed since the dawn of modern Windows. It is not going to go anywhere, in all senses of the phrase: it won't get new features; it won't get support dropped.
Winforms and Windows Forms are the same thing. Winforms is the shortened name for Windows Forms.
You will need to call the EnableVisualStyles
method, which is by default called in the Main
method of the Program
class prior to calling Application.Run
(when you create a Windows Forms project, with the auto-generated code).
This method enables visual styles for the application. Visual styles are the colors, fonts, and other visual elements that form an operating system theme. Controls will draw with 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; typically,EnableVisualStyles()
is the first line in the Main function. A separate manifest is not required to enable visual styles when callingEnableVisualStyles()
.
Make sure that you set the buttons UseVisualStyleBackColor
to true
and that you call Application.EnableVisualStyles();
in your startup code.
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmAddress());
}
}
EDIT: Effect of UseVisualStyleBackColor:
Even if you have Visual Styles enabled (the default), part of the display of the button is controlled by the Operating System, outside the control of your program. The same program running on Windows 7 with the standard interface will look different than when it's running in classic mode.
Bold emphasis added to the excerpt from the documentaiton to illustrate this point.
http://msdn.microsoft.com/en-us/library/y6kzhf8d(VS.80).aspx
Windows XP introduced a new look and feel to the Windows user interface, with controls that have rounded corners and that change color when you pause your mouse over them. By default, Windows-based applications created with Visual Basic automatically support visual styles, also known as Windows XP Themes. When run on a platform that does not support Windows XP Themes, the application reverts to the traditional Windows look and feel. If you do not want your application to support visual styles, you can change the property on the Application page of the Project Designer.
Also from here: http://msdn.microsoft.com/en-us/library/ms171733(VS.80).aspx
in the Checking for Visual Styles Support section.
the following conditions must be true for the visual styles to work:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With