OSFeature 类

提供操作系统特定功能查询。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Class OSFeature
    Inherits FeatureSupport
用法
Dim instance As OSFeature
public class OSFeature : FeatureSupport
public ref class OSFeature : public FeatureSupport
public class OSFeature extends FeatureSupport
public class OSFeature extends FeatureSupport

备注

使用 Feature 属性中提供的此类的 static 实例可查询操作系统功能。不能创建此类的实例。

若要确定功能的版本,请调用 GetVersionPresent 方法。若要确定某个功能或特定版本是否存在,请调用 IsPresent 方法,并使用该类中提供的功能标识符来指定要查找的功能。

示例

下面的示例使用 OSFeature 来查询操作系统,以确定是否安装了 LayeredWindows 功能。该示例提出了两种不同的检查方法来查看该功能是否存在。在第一种方法中,检查 myVersion 以查看它是否为 空引用(在 Visual Basic 中为 Nothing)。如果版本为 空引用(在 Visual Basic 中为 Nothing),则说明未安装该功能。在第二种方法中,示例调用基类方法 IsPresent 以查看是否安装了该功能。结果显示在文本框内。

此代码假定已经创建 textBox1 并将其放置在窗体上。

Private Sub LayeredWindows()
    ' Gets the version of the layered windows feature.
    Dim myVersion As Version = _
       OSFeature.Feature.GetVersionPresent(OSFeature.LayeredWindows)
       
    ' Prints whether the feature is available.
    If Not (myVersion Is Nothing) Then
        textBox1.Text = "Layered windows feature is installed." & _
           ControlChars.CrLf
    Else
        textBox1.Text = "Layered windows feature is not installed." & _
           ControlChars.CrLf
    End If 
    'This is an alternate way to check whether a feature is present.
    If OSFeature.Feature.IsPresent(OSFeature.LayeredWindows) Then
        textBox1.Text &= "Again, layered windows feature is installed."
    Else
        textBox1.Text &= "Again, layered windows feature is not installed."
    End If
End Sub
private void LayeredWindows() {
   // Gets the version of the layered windows feature.
   Version myVersion = OSFeature.Feature.GetVersionPresent(OSFeature.LayeredWindows);

   // Prints whether the feature is available.
   if (myVersion != null)
      textBox1.Text = "Layered windows feature is installed." + '\n';
   else
      textBox1.Text = "Layered windows feature is not installed." + '\n';

   // This is an alternate way to check whether a feature is present.
   if (OSFeature.Feature.IsPresent(OSFeature.LayeredWindows))
      textBox1.Text += "Again, layered windows feature is installed.";
   else
      textBox1.Text += "Again, layered windows feature is not installed.";
}
private:
   void LayeredWindows()
   {
      // Gets the version of the layered windows feature.
      Version^ myVersion = OSFeature::Feature->GetVersionPresent(
         OSFeature::LayeredWindows );
      
      // Prints whether the feature is available.
      if ( myVersion != nullptr )
      {
         textBox1->Text = "Layered windows feature is installed.\n";
      }
      else
      {
         textBox1->Text = "Layered windows feature is not installed.\n";
      }

      
      // This is an alternate way to check whether a feature is present.
      if ( OSFeature::Feature->IsPresent( OSFeature::LayeredWindows ) )
      {
         textBox1->Text = String::Concat( textBox1->Text,
            "Again, layered windows feature is installed." );
      }
      else
      {
         textBox1->Text = String::Concat( textBox1->Text,
            "Again, layered windows feature is not installed." );
      }
   }
private void LayeredWindows()
{
    // Gets the version of the layered windows feature.
    Version myVersion = OSFeature.get_Feature().GetVersionPresent
        (OSFeature.LayeredWindows);

    // Prints whether the feature is available.
    if (myVersion != null) {
        textBox1.set_Text("Layered windows feature is installed." 
            + '\n');
    }
    else {
        textBox1.set_Text("Layered windows feature is not installed." 
            + '\n');
    }

    // This is an alternate way to check whether a feature is present.
    if (OSFeature.get_Feature().IsPresent(OSFeature.LayeredWindows)) {
        textBox1.set_Text(textBox1.get_Text()
            + "Again, layered windows feature is installed.");
    }
    else {
        textBox1.set_Text(textBox1.get_Text() 
            + "Again, layered windows feature is not installed.");
    }
} //LayeredWindows 

继承层次结构

System.Object
   System.Windows.Forms.FeatureSupport
    System.Windows.Forms.OSFeature

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

OSFeature 成员
System.Windows.Forms 命名空间
System.AppDomain
Application 类
System.Environment
SystemInformation