OSFeature.IsPresent(SystemParameter) Método

Definição

Recupera um valor que indica se o sistema operativo suporta a funcionalidade ou métrica especificada.

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

A SystemParameter representa a característica a procurar.

Devoluções

true se a funcionalidade estiver disponível no sistema; caso contrário, false.

Exemplos

O exemplo de código seguinte demonstra como usar o IsPresent método com a SystemParameter enumeração. O exemplo determina se o sistema operativo suporta a CaretWidth métrica antes de chamar a SystemInformation.CaretWidth propriedade.

#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

Observações

Normalmente, utiliza-se o IsPresent método para determinar se o sistema operativo suporta a funcionalidade ou métrica específica identificada por enumValue. Com base no valor devolvido de IsPresent, executarias ações condicionais no teu código. Por exemplo, se chamar este método com um valor de parâmetro de FlatMenu retorno true, pode criar menus desenhados pelo proprietário na sua aplicação num estilo plano.

Aceder a algumas funcionalidades ou métricas do sistema pode gerar exceções se não estiverem disponíveis numa versão específica do sistema operativo. Neste caso, utilize-se primeiro o valor correspondente SystemParameter da enumeração, juntamente com IsPresent, para determinar se a métrica é suportada. Por exemplo, ligue IsPresent para antes CaretWidth de obter o valor da SystemInformation.CaretWidth propriedade.

Aplica-se a

Ver também