OSFeature.IsPresent(SystemParameter) Метод
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
В этой статье
Извлекает значение, показывающее, поддерживает ли операционная система заданную функцию или метрику.
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
- enumVal
- SystemParameter
SystemParameter, представляющий функцию, которую необходимо найти.
Значение true
, если функция доступна в системе, в противном случае — значение false
.
В следующем примере кода показано, как использовать IsPresent метод с перечислением SystemParameter . В этом примере определяется, поддерживает ли операционная система метрику CaretWidth
перед вызовом SystemInformation.CaretWidth свойства.
#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
Как правило, метод используется IsPresent для определения того, поддерживает ли операционная система определенную функцию или метрику, определяемую .enumValue
В зависимости от значения, возвращенного из IsPresent, вы будете выполнять условные действия в коде. Например, при вызове этого метода со значением FlatMenu параметра возвращается true
, можно создать меню, нарисованные владельцем, в приложении в плоском стиле.
Доступ к некоторым системным функциям или метрикам может вызывать исключения, если они недоступны в определенной версии операционной системы. В этом случае сначала используйте соответствующее SystemParameter значение перечисления, а также IsPresentдля определения того, поддерживается ли метрика. Например, вызов с CaretWidth именем IsPresent перед получением SystemInformation.CaretWidth значения свойства.