Redigeeri

Jagamisviis:


OSFeature.IsPresent(SystemParameter) Method

Definition

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

Parameters

enumVal
SystemParameter

A SystemParameter representing the feature to search for.

Returns

true if the feature is available on the system; otherwise, false.

Examples

The following code example demonstrates how to use the IsPresent method with the SystemParameter enumeration. 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

Remarks

Typically, you use the IsPresent method to determine if the operating system supports the specific feature or metric identified by enumValue. Based upon the value returned from IsPresent, you would perform conditional actions in your code. 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. In this case, first use the corresponding SystemParameter enumeration value, along with IsPresent, to determine if the metric is supported. For example, call IsPresent with CaretWidth before getting the SystemInformation.CaretWidth property value.

Applies to

See also