Application.EnableVisualStyles Bug
来源:互联网 发布:163 pop3 端口 编辑:程序博客网 时间:2024/05/22 15:12
Introduction
Version 1.1 of the .NET framework introduced the method System.Windows.Forms.Application.EnableVisualStyles
. Calling this method prior to the creation of any Forms or Controls, will cause Windows XP to apply a theme when rendering Windows Common Controls and many of the native .NET controls like Buttons and CheckBoxes.
Using .NET 1.0, MFC, WTL or VB6, it is necessary to include a manifest, either in the same directory as the executable, or compiled into it as a resource, in order to make use of Windows XP visual styles. While not overly difficult, providing a manifest for every executable one creates is tedious, and Visual Studio has very little tool support for helping you to do so.
The introduction of EnableVisualStyles
to v1.1 of the framework is a nice addition because it allows WinForms applications to easily adopt the new look and feel of Windows XP styles.
The Bug
The problem is that there is bug in the implementation of EnableVisualStyles
that interferes with Images
stored in an ImageList
component and Window Common Controls, like the TreeView
or Toolbar
classes. The effect is that if you call EnableVisualStyles
, all of the images will disappear from your toolbars, treeviews and listviews.
To reproduce the bug:
- Create a WinForms application in VS.NET 2003
- Add a
Toolbar
andImageList
toForm1
- Add an image to the
ImageList
and a button to theToolbar
- Assign the image to the button
- In the
Main
method add a call toApplication.EnableVisualStyles
just before the call toApplication.Run
When you run the app on Windows XP, with a Visual Style active, there will be no image on the toolbar button.
Work Around
After some searching through Google groups I found some discussion of this issue and a work around that seems to work and hasn't caused any problems in my applications. (To read more about the work-around go here)
A call to Application.DoEvents
just after EnableVisualStyles
, seems to fix the problem. How or why, who knows. Most likely it causes some message that was sent via PostMessage
to get flushed out to the correct place, before the creation of the first WinForms based window.
So the work around code looks like this:
void Main() { Application.EnableVisualStyles(); Application.DoEvents(); Application.Run(new Form1()); }
As of yet, I haven't seen any ill effect from the work-around and it seems to always work.
- Application.EnableVisualStyles Bug
- Application.EnableVisualStyles
- Application.EnableVisualStyles
- Application..::.EnableVisualStyles 方法
- Application.EnableVisualStyles方法
- 解决EnableVisualStyles Bug
- Application.EnableVisualStyles()的作用
- Application.EnableVisualStyles()的作用
- Application.EnableVisualStyles()的作用
- Application.EnableVisualStyles()的作用
- C# Program 中Application.EnableVisualStyles()函数
- public static void EnableVisualStyles ()作用
- ListView图片不显示 Application.EnableVisualStyle bug
- Virus Scanner induced bug with ASP.NET webservice application
- Android中application的theme不生效的bug
- 一个奇怪的Bug“Unable to create application ”
- BUG Hunting:PeopleSoft-Application Designer登陆失败 oracle-01017
- WCF BUG has zero application (non-infrastructure) endpoints.
- tomcat 5.5 在Linux下配置 apr
- 缩略图
- StringWriter/PrintWriter
- Debian的APT文档
- css 调用时路径 及 编码格式
- Application.EnableVisualStyles Bug
- JNDI的使用方法及实例
- ping不通的问题解决
- 更改MySQL默认存储目录
- 更改MySQL默认字符集
- 更改MySQL用户口令
- 答非所问,曲解错位
- Tomcat5.5配置应用到根目录
- 8.5,解构主义拼图