Share via


OSFeature.IsPresent(SystemParameter) 方法

定義

擷取值,指出作業系統是否支援指定的功能或度量資訊 (Metric)。

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,表示要搜尋的功能。

傳回

Boolean

如果此功能可以在系統上使用,則為 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 ,以判斷是否支援計量。 例如,在取得 SystemInformation.CaretWidth 屬性值之前呼叫 。 IsPresent CaretWidth

適用於

另請參閱