PropertyGrid 类

提供用于浏览对象属性的用户界面。

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

语法

声明
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class PropertyGrid
    Inherits ContainerControl
    Implements IComPropertyBrowser
用法
Dim instance As PropertyGrid
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class PropertyGrid : ContainerControl, IComPropertyBrowser
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
[ComVisibleAttribute(true)] 
public ref class PropertyGrid : public ContainerControl, IComPropertyBrowser
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class PropertyGrid extends ContainerControl implements IComPropertyBrowser
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class PropertyGrid extends ContainerControl implements IComPropertyBrowser

备注

要使用属性网格,应在父控件上创建 PropertyGrid 类的新实例,并将 SelectedObject 设置成要为其显示属性的对象。

网格中显示的信息是分配对象时的属性快照。如果在运行时从代码中更改了由 SelectedObject 指定的对象的属性值,则一直要到在网格中执行了某个操作而使网格刷新时,才会显示新值。

属性网格中的属性选项卡作为按钮显示在 PropertyGrid 顶部的工具栏上,并且可以在 PropertyTabScope 中定义的范围内变化。

PropertyGrid 控件最初并不在开发环境的工具箱中提供。可以将属性网格添加到工具箱中,以便将 PropertyGrid 拖到窗体中。您还可以通过在源代码中添加相应的代码来定义 PropertyGrid 的实例。

示例

下面的代码示例演示如何创建属性网格并设置它在窗体中的位置。本示例要求有一个含有 TextBox 的窗体。

public Form1() {

   // The initial constructor code goes here.
 
   PropertyGrid propertyGrid1 = new PropertyGrid();
   propertyGrid1.CommandsVisibleIfAvailable = true;
   propertyGrid1.Location = new Point(10, 20);
   propertyGrid1.Size = new System.Drawing.Size(400, 300);
   propertyGrid1.TabIndex = 1;
   propertyGrid1.Text = "Property Grid";

   this.Controls.Add(propertyGrid1);

   propertyGrid1.SelectedObject = textBox1;
}
public:
   [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
   Form1()
   {
      // The initial constructor code goes here.

      PropertyGrid^ propertyGrid1 = gcnew PropertyGrid;
      propertyGrid1->CommandsVisibleIfAvailable = true;
      propertyGrid1->Location = Point( 10, 20 );
      propertyGrid1->Size = System::Drawing::Size( 400, 300 );
      propertyGrid1->TabIndex = 1;
      propertyGrid1->Text = "Property Grid";

      this->Controls->Add( propertyGrid1 );

      propertyGrid1->SelectedObject = textBox1;
   }

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ContainerControl
            System.Windows.Forms.PropertyGrid

线程安全

此类型的任何公共静态(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

请参见

参考

PropertyGrid 成员
System.Windows.Forms 命名空间
PropertyTabScope