找回密码
 立即注册

QQ登录

只需一步,快速开始

graper

高级会员

45

主题

63

帖子

1348

积分

高级会员

积分
1348

活字格认证

graper
高级会员   /  发表于:2009-12-11 14:50  /   查看:5811  /  回复:0
Post by "Leo", 01-16-2007, 15:52
-----------------------------------------------------


为了保持控件风格的统一,在做控件开发的时候我们通常要判断一个Control何时应当按照Theme画法绘制,合适采用经典3D画法。

.NET 2.0在System.Windows.Forms.Application类中间提供了相关的支持。

System.Windows.Forms.Application.RenderWithVisualStyles property
这个是我们通常知道的判断当前Application是否支持Theme的方法。通过判断该静态属性为true of false而得到当前的App是否是支持Theme画法的。MSDN中间相关解释如下:
Gets a value specifying whether the current application is drawing controls with visual styles
If you are drawing a custom control, use this property to decide whether to draw the control with or without visual styles, so that its appearance is consistent with other controls in the application.
The following table shows the four conditions that must exist for RenderWithVisualStyles to return true.

Condition
Description

The operating system supports visual styles
To verify this condition separately, use the IsSupportedByOS property of the VisualStyleInformation class.

The user has enabled visual styles in the operating system
To verify this condition separately, use the IsEnabledByUser property of the VisualStyleInformation class.

Visual styles are enabled in the application
Visual styles can be enabled in an application by calling the EnableVisualStyles method or by using an application manifest that specifies that ComCtl32.dll version 6 or later will be used to draw controls.

Visual styles are being used to draw the client area of application windows
To verify this condition separately, use the VisualStyleState property of the Application class and verify that it has the value VisualStyleState.ClientAreaEnabled or VisualStyleState.ClientAndNonClientAreasEnabled.


System.Windows.Forms.VisualStylesState{get; set;} property.
This property will always be ignored by us, but it really can take effect. If will be set to determing whether the visual style can take effect on Client area or None-Client area.
Here I have attached a simple sample to show how the property can works.
Summarize: We have to check the RenderWithVisualStyles property first to determing whether the Visual Theme is supported by OS and the application. Then we have to check whether the VisualStyleState is one of the following value:
  Member name Description
ClientAndNonClientAreasEnabled Visual styles are applied to client and nonclient areas.  
ClientAreaEnabled Visual styles are applied only to the client area.  
NonClientAreaEnabled Visual styles are applied only to the nonclient area.  
NoneEnabled Visual styles are not applied to the application.



For instance, if the visual style is only enabled in ClientArea, when we draw None client area of our control, we can not use theme to draw our control.

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部