Bagikan melalui


OSFeature.IsPresent(SystemParameter) Metode

Definisi

Mengambil nilai yang menunjukkan apakah sistem operasi mendukung fitur atau metrik yang ditentukan.

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

Parameter

enumVal
SystemParameter

Mewakili SystemParameter fitur yang akan dicari.

Mengembalikan

true jika fitur tersedia pada sistem; jika tidak, false.

Contoh

Contoh kode berikut menunjukkan cara menggunakan IsPresent metode dengan SystemParameter enumerasi. Contoh menentukan apakah sistem operasi mendukung CaretWidth metrik sebelum memanggil SystemInformation.CaretWidth properti .

#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

Keterangan

Biasanya, Anda menggunakan IsPresent metode untuk menentukan apakah sistem operasi mendukung fitur atau metrik tertentu yang diidentifikasi oleh enumValue. Berdasarkan nilai yang dikembalikan dari IsPresent, Anda akan melakukan tindakan bersyarah dalam kode Anda. Misalnya, jika memanggil metode ini dengan nilai FlatMenu parameter pengembalian true, Anda dapat membuat menu yang digambar pemilik di aplikasi Anda dengan gaya datar.

Mengakses beberapa fitur atau metrik sistem dapat menimbulkan pengecualian jika tidak tersedia pada versi sistem operasi tertentu. Dalam hal ini, pertama-tama gunakan nilai enumerasi yang SystemParameter sesuai, bersama dengan IsPresent, untuk menentukan apakah metrik didukung. Misalnya, hubungi IsPresent dengan CaretWidth sebelum mendapatkan SystemInformation.CaretWidth nilai properti.

Berlaku untuk

Lihat juga