Freigeben über


OSFeature.IsPresent(SystemParameter) Methode

Definition

Ruft einen Wert ab, der angibt, ob das Betriebssystem das angegebene Feature oder die angegebene Metrik unterstützt.

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

Parameter

enumVal
SystemParameter

A SystemParameter representing the feature to search for.

Gibt zurück

truewenn das Feature im System verfügbar ist; andernfalls . false

Beispiele

Im folgenden Codebeispiel wird die Verwendung der IsPresent Methode mit der SystemParameter Enumeration veranschaulicht. Im Beispiel wird ermittelt, ob das Betriebssystem die CaretWidth Metrik vor dem Aufrufen der SystemInformation.CaretWidth Eigenschaft unterstützt.

#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

Hinweise

In der Regel verwenden Sie die IsPresent Methode, um zu ermitteln, ob das Betriebssystem das bestimmte Feature oder die metrik unterstützt, die durch enumValue. Basierend auf dem von IsPresentIhnen zurückgegebenen Wert würden Sie bedingte Aktionen in Ihrem Code ausführen. Wenn Sie diese Methode z. B. mit einem Parameterwert von FlatMenu "Returns true" aufrufen, können Sie in Ihrer Anwendung in einer flachen Formatvorlage gezeichnete Menüs erstellen.

Der Zugriff auf einige Systemfeatures oder Metriken kann Ausnahmen auslösen, wenn sie in einer bestimmten Betriebssystemversion nicht verfügbar sind. Verwenden Sie in diesem Fall zuerst den entsprechenden SystemParameter Enumerationswert zusammen mit IsPresentdem, um zu ermitteln, ob die Metrik unterstützt wird. Rufen Sie z. BIsPresent. vor dem Abrufen des Eigenschaftswerts SystemInformation.CaretWidth aufCaretWidth.

Gilt für:

Weitere Informationen