OSFeature.IsPresent(SystemParameter) Método

Definición

Recupera un valor que indica si el sistema operativo admite la característica o la métrica especificadas.

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

Parámetros

enumVal
SystemParameter

Un objeto SystemParameter que representa la característica que se va a buscar.

Devoluciones

Boolean

true si la característica está disponible en el sistema; de lo contrario, false.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el IsPresent método con la SystemParameter enumeración . En el ejemplo se determina si el sistema operativo admite la CaretWidth métrica antes de llamar a la SystemInformation.CaretWidth propiedad .

#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

Comentarios

Normalmente, se usa el IsPresent método para determinar si el sistema operativo admite la característica o métrica específica identificada por enumValue. En función del valor devuelto de IsPresent, realizaría acciones condicionales en el código. Por ejemplo, si se llama a este método con un valor de parámetro de FlatMenu devuelve true, podría crear menús dibujados por el propietario en la aplicación en un estilo plano.

El acceso a algunas características o métricas del sistema puede generar excepciones si no están disponibles en una versión específica del sistema operativo. En este caso, use primero el valor de enumeración correspondiente SystemParameter , junto con IsPresent, para determinar si se admite la métrica. Por ejemplo, llame a IsPresent con CaretWidth antes de obtener el valor de la SystemInformation.CaretWidth propiedad.

Se aplica a

Consulte también