OSFeature.IsPresent(SystemParameter) Méthode

Définition

Récupère une valeur indiquant si le système d'exploitation prend en charge la fonctionnalité ou le métrique spécifié(e).

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

Paramètres

enumVal
SystemParameter

SystemParameter représentant la fonctionnalité à rechercher.

Retours

Boolean

true si la fonctionnalité est disponible sur le système ; sinon, false.

Exemples

L’exemple de code suivant montre comment utiliser la IsPresent méthode avec l’énumération SystemParameter . L’exemple détermine si le système d’exploitation prend en charge la CaretWidth métrique avant d’appeler la SystemInformation.CaretWidth propriété.

#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

Remarques

En règle générale, vous utilisez la IsPresent méthode pour déterminer si le système d’exploitation prend en charge la fonctionnalité ou la métrique spécifique identifiée par enumValue. En fonction de la valeur retournée par IsPresent, vous devez effectuer des actions conditionnelles dans votre code. Par exemple, si vous appelez cette méthode avec une valeur de paramètre de FlatMenu retour true, vous pouvez créer des menus dessinés par le propriétaire dans votre application dans un style plat.

L’accès à certaines fonctionnalités système ou métriques peut déclencher des exceptions si elles ne sont pas disponibles sur une version spécifique du système d’exploitation. Dans ce cas, utilisez d’abord la valeur d’énumération correspondante SystemParameter , ainsi que IsPresent, pour déterminer si la métrique est prise en charge. Par exemple, appelez-le IsPresent CaretWidth avant d’obtenir la valeur de la SystemInformation.CaretWidth propriété.

S’applique à

Voir aussi