OSFeature.IsPresent(SystemParameter) OSFeature.IsPresent(SystemParameter) OSFeature.IsPresent(SystemParameter) OSFeature.IsPresent(SystemParameter) Method

定义

检索一个值,该值指示操作系统是否支持指定的功能或规格。Retrieves a value indicating whether the operating system supports the specified feature or metric.

public:
 static bool IsPresent(System::Windows::Forms::SystemParameter enumVal);
public static bool IsPresent (System.Windows.Forms.SystemParameter enumVal);
static member IsPresent : System.Windows.Forms.SystemParameter -> bool
Public Shared Function IsPresent (enumVal As SystemParameter) As Boolean

参数

enumVal
SystemParameter SystemParameter SystemParameter SystemParameter

SystemParameter,表示要搜索的功能。A SystemParameter representing the feature to search for.

返回

如果功能在系统中可用,则为 true;否则为 falsetrue if the feature is available on the system; otherwise, false.

示例

下面的代码示例演示如何将IsPresent方法SystemParameter与枚举一起使用。The following code example demonstrates how to use the IsPresent method with the SystemParameter enumeration. 该示例在SystemInformation.CaretWidth调用属性之前确定操作系统是否CaretWidth支持该度量值。The example determines if the operating system supports the CaretWidth metric before calling the SystemInformation.CaretWidth property.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Gets the caret width based upon the operating system or default value.
int GetCaretWidth()
{
   // Check to see if the operating system supports the caret width metric. 
   if ( OSFeature::Feature->IsPresent( SystemParameter::CaretWidthMetric ) )
   {
      // If the operating system supports this metric,
      // return the value for the caret width metric. 
      return SystemInformation::CaretWidth;
   }
   else
         1;

   // If the operating system does not support this metric,
   // return a custom default value for the caret width.
}
// 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;
}
' Gets the caret width based upon the operating system or default value.
Private Function GetCaretWidth() As Integer

    ' Check to see if the operating system supports the caret width metric. 
    If OSFeature.IsPresent(SystemParameter.CaretWidthMetric) Then

        ' 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
    End If
End Function

注解

通常, 使用IsPresent方法来确定操作系统是否支持由enumValue标识的特定功能或指标。Typically, you use the IsPresent method to determine if the operating system supports the specific feature or metric identified by enumValue. 根据从IsPresent返回的值, 您可以在代码中执行条件操作。Based upon the value returned from IsPresent, you would perform conditional actions in your code. 例如, 如果使用的FlatMenu true参数值调用此方法, 则可以在应用程序中以平面样式创建所有者描述的菜单。For example, if calling this method with a parameter value of FlatMenu returns true, you could create owner-drawn menus in your application in a flat style.

如果在特定操作系统版本上不可用, 则访问某些系统功能或指标可能会引发异常。Accessing some system features or metrics can raise exceptions if they are not available on a specific operating system version. 在这种情况下, 首先使用SystemParameter相应的枚举值IsPresent和来确定是否支持此指标。In this case, first use the corresponding SystemParameter enumeration value, along with IsPresent, to determine if the metric is supported. 例如, CaretWidth在获取IsPresent SystemInformation.CaretWidth属性值之前调用。For example, call IsPresent with CaretWidth before getting the SystemInformation.CaretWidth property value.

适用于

另请参阅