OSFeature.IsPresent(SystemParameter) Metoda

Definice

Načte hodnotu označující, jestli operační systém podporuje zadanou funkci nebo metriku.

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

Parametry

enumVal
SystemParameter

Reprezentace SystemParameter funkce, kterou chcete vyhledat.

Návraty

Boolean

true je-li tato funkce k dispozici v systému; falsev opačném případě .

Příklady

Následující příklad kódu ukazuje, jak použít metodu IsPresent s výčtem SystemParameter . Příklad určuje, jestli operační systém podporuje metriku CaretWidth před voláním SystemInformation.CaretWidth vlastnosti.

#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

Poznámky

Metodu IsPresent obvykle používáte k určení, jestli operační systém podporuje konkrétní funkci nebo metriku identifikovanou .enumValue Na základě hodnoty vrácené z IsPresentkódu byste v kódu provedli podmíněné akce. Pokud například voláte tuto metodu s hodnotou parametru návratu FlatMenu true, můžete v aplikaci vytvořit nabídky vykreslené vlastníkem v plochém stylu.

Přístup k některým systémovým funkcím nebo metrikám může vyvolat výjimky, pokud nejsou k dispozici v konkrétní verzi operačního systému. V tomto případě nejprve použijte odpovídající SystemParameter hodnotu výčtu spolu s parametrem IsPresenta určete, jestli je metrika podporovaná. Například voláním IsPresent před získáním CaretWidth SystemInformation.CaretWidth hodnoty vlastnosti.

Platí pro

Viz také