OSFeature.IsPresent(SystemParameter) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Recupera un valore che indica se il sistema operativo supporta la funzionalità o la metrica specificata.
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
Parametri
- enumVal
- SystemParameter
Oggetto SystemParameter che rappresenta la funzionalità da cercare.
Restituisce
true se la funzionalità è disponibile nel sistema; in caso contrario, false.
Esempio
Nell'esempio di codice seguente viene illustrato come utilizzare il IsPresent metodo con l'enumerazione SystemParameter . L'esempio determina se il sistema operativo supporta la CaretWidth metrica prima di chiamare la SystemInformation.CaretWidth proprietà .
#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
Commenti
In genere, si usa il IsPresent metodo per determinare se il sistema operativo supporta la funzionalità o la metrica specifica identificata da enumValue. In base al valore restituito da IsPresent, è possibile eseguire azioni condizionali nel codice. Ad esempio, se la chiamata a questo metodo con un valore di parametro restituisce FlatMenutrue, è possibile creare menu disegnati dal proprietario nell'applicazione in uno stile flat.
L'accesso ad alcune funzionalità o metriche di sistema può generare eccezioni se non sono disponibili in una versione specifica del sistema operativo. In questo caso, usare prima di tutto il valore di enumerazione corrispondente SystemParameter , insieme IsPresenta , per determinare se la metrica è supportata. Ad esempio, chiamare IsPresent con CaretWidth prima di ottenere il valore della SystemInformation.CaretWidth proprietà.