OSFeature.IsPresent(SystemParameter) 方法

定义

检索一个值,该值指示操作系统是否支持指定的功能或规格。

C#
public static bool IsPresent (System.Windows.Forms.SystemParameter enumVal);

参数

enumVal
SystemParameter

SystemParameter,表示要搜索的功能。

返回

Boolean

如果功能在系统中可用,则为 true;否则为 false

示例

下面的代码示例演示如何将 IsPresent 该方法用于 SystemParameter 枚举。 该示例确定操作系统在调用SystemInformation.CaretWidth属性之前是否支持CaretWidth指标。

C#
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
C#
// Gets the caret width based upon the operating system or default value.
private int GetCaretWidth ()
{    

    // Check to see if the operating system supports the caret width metric. 
    if (OSFeature.IsPresent(SystemParameter.CaretWidthMetric))
    {

        // If the operating system supports this metric,
        // return the value for the caret width metric. 

        return SystemInformation.CaretWidth;
    } else
    {

        // If the operating system does not support this metric,
        // return a custom default value for the caret width.

        return 1;
    }
}

注解

通常,使用 IsPresent 此方法确定操作系统是否支持通过 enumValue标识的特定功能或指标。 根据从中 IsPresent返回的值,你将在代码中执行条件操作。 例如,如果使用返回true的参数值FlatMenu调用此方法,则可以在应用程序中以平面样式创建所有者绘制的菜单。

如果某些系统功能或指标在特定操作系统版本上不可用,则访问某些系统功能或指标可能会引发异常。 在这种情况下,首先使用相应的 SystemParameter 枚举值以及 IsPresent确定是否支持指标。 例如,在获取SystemInformation.CaretWidth属性值之前调用IsPresentCaretWidth

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅