OSFeature.IsPresent(SystemParameter) Método

Definição

Recupera um valor que indica se o sistema operacional é compatível com recursos ou métricas especificados.

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

Um SystemParameter que representa o recurso a ser pesquisado.

Retornos

Boolean

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

Exemplos

O exemplo de código a seguir demonstra como usar o IsPresent método com a SystemParameter enumeração. O exemplo determina se o sistema operacional dá suporte à 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

Comentários

Normalmente, você usa o IsPresent método para determinar se o sistema operacional dá suporte ao recurso ou métrica específico identificado por enumValue. Com base no valor retornado, IsPresentvocê executaria ações condicionais em seu código. Por exemplo, se chamar esse método com um valor de parâmetro de FlatMenu retorno true, você poderá criar menus desenhados pelo proprietário em seu aplicativo em um estilo simples.

Acessar alguns recursos ou métricas do sistema poderá gerar exceções se eles não estiverem disponíveis em uma versão específica do sistema operacional. Nesse caso, primeiro use o valor de enumeração correspondente SystemParameter , juntamente com IsPresent, para determinar se a métrica tem suporte. Por exemplo, chame IsPresent com CaretWidth antes de obter o valor da SystemInformation.CaretWidth propriedade.

Aplica-se a

Confira também