·天新网首页·加入收藏·设为首页
首页|笔记本|手机|数码相机|摄像机|MP3/MP4|主板|内存|显示器|办公|打印机|下载|开发|汽车|学院|业界
硬件|台式机|数码|数字家庭|投影仪|GPS/CPU|显卡|硬盘|服务器|网络|一体机|驱动|源码|游戏|考试|报价
您现在的位置:天新网 > 软件开发 > 开发文摘 > .Net文摘
充分利用.NET 框架的PropertyGrid 控件
http://dev.21tx.com 2002年08月28日 Microsoft

1 2 3 4 5 6 7 8 下一页

  摘要:本文旨在帮助您了解 Microsoft .net 框架中的 PropertyGrid 控件,以及如何针对您的应用程序自定义该控件。

  PropertyGrid 控件简介

  如果您使用过 Microsoft® Visual Basic® 或 Microsoft Visual Studio .NET,那么您一定使用过属性浏览器来浏览、查看和编辑一个或多个对象的属性。.NET 框架 PropertyGrid 控件是 Visual Studio .NET 属性浏览器的核心。PropertyGrid 控件显示对象或类型的属性,并主要通过使用反射来检索项目的属性。(反射是在运行时提供类型信息的技术。)

  下面的屏幕快照显示了 PropertyGrid 在窗体上的外观。

图 1:窗体上的 PropertyGrid

  PropertyGrid 包含以下部分:

  • 属性
  • 可展开属性
  • 属性类别标题
  • 属性说明
  • 属性编辑器
  • 属性选项卡
  • 命令窗格(显示控件设计器提供的设计器操作)
  创建 PropertyGrid 控件

  要使用 Visual Studio .NET 创建 PropertyGrid 控件,需要将该控件添加到工具箱中,因为默认情况下并不包含该控件。在 Tools(工具)菜单中,选择 Customize Toolbox(自定义工具箱)。在对话框中选择 Framework Components(框架组件)选项卡,然后选择 PropertyGrid

  如果您从命令行编译代码,请使用 /reference 选项并指定 System.Windows.Forms.dll。

  以下代码显示了如何创建 PropertyGrid 控件并将其添加到窗体中。

' Visual Basic

Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Globalization

Public Class OptionsDialog
Inherits System.Windows.Forms.Form

Private OptionsPropertyGrid As System.Windows.Forms.PropertyGrid

Public Sub New()
MyBase.New()

OptionsPropertyGrid = New PropertyGrid()
OptionsPropertyGrid.Size = New Size(300, 250)

Me.Controls.Add(OptionsPropertyGrid)
Me.Text = "选项对话框"
End Sub
End Class


//C#

using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Globalization;

public class OptionsDialog : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid OptionsPropertyGrid;
public OptionsDialog()
{
OptionsPropertyGrid = new PropertyGrid();
OptionsPropertyGrid.Size = new Size(300, 250);

this.Controls.Add(OptionsPropertyGrid);
this.Text = "选项对话框";
}

[STAThread]
static void Main()
{
Application.Run(new OptionsDialog());
}
}

上一篇: Delphi 7前瞻:将Delphi作为ASP.NET的脚本语言(上)
下一篇: StreamWriter输出中文乱码的问题

1 2 3 4 5 6 7 8 下一页

Google
 
热点文章
关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图
Copyright © 2000-2008 , www.21tx.com , All Rights Reserved .
晨新科技 版权所有 Created by TXSite.net