收藏 分销(赏)

System.Windows.Forms层次结构.doc

上传人:xrp****65 文档编号:6768256 上传时间:2024-12-21 格式:DOC 页数:8 大小:190.50KB 下载积分:10 金币
下载 相关 举报
System.Windows.Forms层次结构.doc_第1页
第1页 / 共8页
System.Windows.Forms层次结构.doc_第2页
第2页 / 共8页


点击查看更多>>
资源描述
System.Windows.Forms的层次结构,在树图中显示 ★在Visual Studio 中新建Winform应用程序YlqForm,新建一个windows窗体 GetClassForm,窗体GetClassForm中加入TreeView:tvList,RichTextBox: richTextBox1, Button:btnFind,以及两个Label 如下图所示: ★程序源代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace YlqForm { public partial class GetClassForm : Form { DataTable dtClass = new DataTable(); public GetClassForm() { InitializeComponent(); } /// <summary> /// 获得System.Windows.Forms类的层次表 /// 返回数据表的列名有:ClassName,BaseClassName,Remark /// </summary> /// <returns></returns> private DataTable GetDataTable() { DataTable dt = new DataTable(); /* * 列ClassName ---类名如Label * 列BaseClassName ---基类名如Control。联合为一起即Label : Control * 列Remark ---类(如:Label)的详细说明 */ dt.Columns.Add("ClassName", typeof(string)); dt.Columns.Add("BaseClassName", typeof(string)); dt.Columns.Add("Remark", typeof(string)); /* * 数据详细行 * 依次输入ClassName、BaseClassName、Remark * 如"Label","Control","表示标准Windows 标签。" */ #region 层次结构的根 dt.Rows.Add("System.MarshalByRefObject", "System.Object", "允许在支持远程处理的应用程序中跨应用程序域边界访问对象。"); dt.Rows.Add("Component", "System.MarshalByRefObject", "提供System.ComponentModel.IComponent 接口的基实现并启用应用程序之间的对象共享。"); #endregion #region 基本System.Windows.Forms控件类 dt.Rows.Add("Button", "ButtonBase", "表示Windows 按钮控件。"); dt.Rows.Add("CheckBox", "ButtonBase", "表示Windows System.Windows.Forms.CheckBox"); dt.Rows.Add("CheckedListBox", "ListBox", "显示一个System.Windows.Forms.ListBox,其中在每项的左边显示一个复选框。"); dt.Rows.Add("ColorDialog", "CommonDialog", "表示一个通用对话框,该对话框显示可用的颜色以及允许用户定义自定义颜色的控件。"); dt.Rows.Add("ComboBox", "ListControl", "表示Windows 组合框控件。"); dt.Rows.Add("ContextMenuStrip", "ToolStripDropDownMenu", "表示快捷菜单。"); dt.Rows.Add("DataGridView", "Control", "在可自定义的网格中显示数据。"); dt.Rows.Add("DateTimePicker", "Control", "表示一个Windows 控件,该控件用来让用户选择日期和时间并以指定的格式显示此日期和时间。"); dt.Rows.Add("DomainUpDown", "UpDownBase", "表示显示字符串值的Windows 数字显示框(也称为up-down 控件)。"); dt.Rows.Add("ErrorProvider", "Component", "提供用于指示窗体上的控件具有关联错误的用户界面。"); dt.Rows.Add("EventLog", "Component", "提供与Windows 事件日志的交互。"); //System.Diagnostics.EventLog dt.Rows.Add("FlowLayoutPanel", "Panel", "表示一个沿着水平或垂直方向动态排放其内容的面板。"); dt.Rows.Add("FolderBrowserDialog", "CommonDialog", "提示用户选择文件夹。无法继承此类。"); dt.Rows.Add("FontDialog", "CommonDialog", "提示用户从本地计算机上安装的字体中选择一种字体。"); dt.Rows.Add("GroupBox", "Control", "表示一个Windows 控件,该控件显示围绕一组具有可选标题的控件的框架。"); dt.Rows.Add("HelpProvider", "Component", "提供控件的弹出或联机帮助。"); dt.Rows.Add("HScrollBar", "ScrollBar", "表示一个标准Windows 水平滚动条。"); dt.Rows.Add("ImageList", "Component", "提供管理System.Drawing.Image 对象集合的方法。无法继承此类。"); dt.Rows.Add("Label", "Control", "表示标准Windows 标签。"); dt.Rows.Add("LinkLabel", "Label", "表示可显示超链接的Windows 标签控件。"); dt.Rows.Add("ListBox", "ListControl", "表示用于显示项列表的Windows 控件。"); dt.Rows.Add("ListView", "Control", "表示Windows 列表视图控件,该控件显示可用四种不同视图之一显示的项集合。"); dt.Rows.Add("MaskedTextBox", "TextBoxBase", "使用掩码区分正确和不正确的用户输入。"); dt.Rows.Add("MenuStrip", "ToolStrip", "提供窗体的菜单系统。"); dt.Rows.Add("MonthCalendar", "Control", "表示一个Windows 控件,该控件使用户能够使用可视月历显示来选择日期。"); dt.Rows.Add("NotifyIcon", "NotifyIcon", "指定在通知区域中创建图标的组件。无法继承此类。"); dt.Rows.Add("NumericUpDown", "UpDownBase", "表示显示数值的Windows 数字显示框(也称作up-down 控件)。"); dt.Rows.Add("OpenFileDialog", "FileDialog", "提示用户打开文件。无法继承此类。"); dt.Rows.Add("PageSetupDialog", "CommonDialog", "允许用户更改与页面相关的打印设置,包括边距和纸张方向。无法继承此类。"); dt.Rows.Add("Panel", "ScrollableControl", "用于对控件集合进行分组。"); dt.Rows.Add("PerformanceCounter", "Component", "表示Windows NT 性能计数器组件。");//System.Diagnostics.PerformanceCounter dt.Rows.Add("PictureBox", "Control", "表示用于显示图像的Windows 图片框控件。"); dt.Rows.Add("PrintDialog", "CommonDialog", "允许用户从Windows 窗体应用程序中选择一台打印机,并选择文档中要打印的部分。"); dt.Rows.Add("PrintPreviewControl", "Control", "表示Windows 窗体应用程序打印预览的原始预览部分,没有任何对话框或按钮。"); dt.Rows.Add("Process", "Component", "提供对本地和远程进程的访问并使您能够启动和停止本地系统进程。");//System.Diagnostics.Process dt.Rows.Add("ProgressBar", "Control", "表示Windows 进度栏控件。"); dt.Rows.Add("PropertyGrid", "ContainerControl", "提供用于浏览对象属性的用户界面。"); dt.Rows.Add("RadioButton", "ButtonBase", "当与其他System.Windows.Forms.RadioButton 控件成对出现时,使用户能够从一组选项中选择一个选项。"); dt.Rows.Add("RichTextBox", "TextBoxBase", "表示Windows 多格式文本框控件。"); dt.Rows.Add("SaveFileDialog", "FileDialog", "提示用户选择文件的保存位置。无法继承此类。"); dt.Rows.Add("SerialPort", "Component", "表示串行端口资源。");//System.IO.Ports.SerialPort dt.Rows.Add("ServiceController", "Component", "表示Windows 服务并允许连接到正在运行或者已停止的服务、对其进行操作或获取有关它的信息。"); //System.ServiceProcess.ServiceController; //需要添加引用 dt.Rows.Add("SplitContainer", "ContainerControl", "表示一个由可移动条组成的控件,该可移动条将容器的显示区域分成两个大小可调的面板。"); dt.Rows.Add("StatusStrip", "ToolStrip", "表示Windows 状态栏控件。"); dt.Rows.Add("TabControl", "Control", "管理相关的选项卡页集。"); dt.Rows.Add("TableLayoutPanel", "Panel", "表示一个面板,它可以在一个由行和列组成的网格中对其内容进行动态布局。"); dt.Rows.Add("TextBox", "TextBoxBase", "表示Windows 文本框控件。"); dt.Rows.Add("Timer", "Component", "实现按用户定义的时间间隔引发事件的计时器。此计时器最宜用于Windows 窗体应用程序中,并且必须在窗口中使用。");//System.Windows.Forms.Timer dt.Rows.Add("ToolStrip", "ScrollableControl", "为Windows 工具栏对象提供容器。"); dt.Rows.Add("ToolStripContainer", "ContainerControl", "在窗体的每一侧提供面板,并提供可以容纳一个或多个控件的中间面板。"); dt.Rows.Add("TrackBar", "Control", "表示一个标准的Windows 跟踪条。"); dt.Rows.Add("TreeView", "Control", "显示标记项的分层集合,每个标记项用一个System.Windows.Forms.TreeNode 来表示。"); dt.Rows.Add("VScrollBar", "ScrollBar", "表示标准的Windows 垂直滚动条。"); dt.Rows.Add("WebBrowser", "WebBrowserBase", "使用户可以在窗体中导航网页。"); dt.Rows.Add("ReportViewer", "UserControl", "封装用于ReportViewer 控件的方法和属性。");//Microsoft.Reporting.WinForms.ReportViewer dt.Rows.Add("Form", "ContainerControl", "表示组成应用程序的用户界面的窗口或对话框。"); #endregion #region System.Windows.Forms控件类的基类 dt.Rows.Add("ButtonBase", "Control", "实现按钮控件共同的基本功能。"); dt.Rows.Add("ListControl", "Control", "为System.Windows.Forms.ListBox 类和System.Windows.Forms.ComboBox 类提供一个共同的成员实现方法。"); dt.Rows.Add("CommonDialog", "Component", "指定用于在屏幕上显示对话框的基类。"); dt.Rows.Add("Control", "Component", "定义控件的基类,控件是带有可视化表示形式的组件。实现了定义鼠标事件IDropTarget。"); dt.Rows.Add("UpDownBase", "ContainerControl", "实现数字显示框(也称为up-down 控件)所需的基本功能。"); dt.Rows.Add("ScrollBar", "Control", "实现滚动条控件的基本功能。"); dt.Rows.Add("TextBoxBase", "Control", "实现文本控件要求的基本功能。"); dt.Rows.Add("FileDialog", "CommonDialog", "显示一个用户可从中选择文件的对话框窗口。"); dt.Rows.Add("ContainerControl", "ScrollableControl", "为可用作其他控件的容器的控件提供焦点管理功能。"); dt.Rows.Add("ScrollableControl", "Control", "为支持自动滚动行为的控件定义一个基类。"); dt.Rows.Add("WebBrowserBase", "Control", "为泛型ActiveX 控件提供包装以便由System.Windows.Forms.WebBrowser 控件用作基类。"); dt.Rows.Add("UserControl", "ContainerControl", "提供一个可用来创建其他控件的空控件。"); dt.Rows.Add("ToolStripDropDownMenu", "ToolStripDropDown", "提供System.Windows.Forms.ContextMenuStrip 控件的基本功能。"); dt.Rows.Add("ToolStripDropDown", "ToolStrip", "表示当用户单击System.Windows.Forms.ToolStripDropDownButton 时,使用户可以从列表中选择单个项的控件。"); #endregion return dt; } /// <summary> /// 查看按钮的点击事件 /// </summary> private void btnFind_Click(object sender, EventArgs e) { //System.Object为根节点 tvList.Nodes.Clear(); TreeNode rootNode = tvList.Nodes.Add("System.Object"); rootNode.Tag = "支持.NET Framework 类层次结构中的所有类,并为派生类提供低级别服务。这是.NET Framework 中所有类的最终基类;它是类型层次结构的根。"; DataTable dt = GetNewDataTable(dtClass, string.Format("BaseClassName='{0}'", "System.Object")); BindTreeView(dt, rootNode.Nodes); tvList.ExpandAll(); } /// <summary> /// 绑定TreeView /// </summary> /// <param name="dt">满足父节点的表</param> /// <param name="nodes">节点的集合</param> public void BindTreeView(DataTable dt, TreeNodeCollection nodes) { for (int i = 0; i < dt.Rows.Count; i++) { TreeNode tempNode = new TreeNode(); tempNode.Text = dt.Rows[i]["ClassName"].ToString(); tempNode.Tag = dt.Rows[i]["Remark"].ToString(); nodes.Add(tempNode); //以当前节点的ClassName作为基类,查看该节点下的子类 DataTable subDataTable = GetNewDataTable(dtClass, string.Format("BaseClassName='{0}'", dt.Rows[i]["ClassName"].ToString())); if (subDataTable.Rows.Count > 0) { BindTreeView(subDataTable, tempNode.Nodes); } } } /// <summary> /// 执行DataTable中的查询返回新的DataTable /// </summary> /// <param name="dt">源数据DataTable</param> /// <param name="condition">查询条件如id='a5'</param> /// <returns></returns> public static DataTable GetNewDataTable(DataTable dt, string condition) { DataTable newdt = new DataTable(); newdt = dt.Clone(); DataRow[] dr = dt.Select(condition); for (int i = 0; i < dr.Length; i++) { newdt.ImportRow(dr[i]); } return newdt;//返回的查询结果 } /// <summary> /// 窗体GetClassForm的Load事件 /// </summary> private void GetClassForm_Load(object sender, EventArgs e) { dtClass = GetDataTable(); } /// <summary> /// 在选定树节点后发生。 /// </summary> private void tvList_AfterSelect(object sender, TreeViewEventArgs e) { if (tvList.SelectedNode == null) { richTextBox1.Text = ""; return; } TreeNode node = tvList.SelectedNode; //子节点集合 StringBuilder sb = new StringBuilder(); for (int i = 0; i < node.Nodes.Count; i++) { sb.AppendFormat("{0}:{1}\n", node.Nodes[i].Text, Convert.ToString(node.Nodes[i].Tag)); } richTextBox1.Text = string.Format("当前类:{0}\n说明:{1}\n\n继承的父类:\n{2}:{3}\n\n子类列表:\n{4}", node.Text, Convert.ToString(node.Tag), node.Parent == null ? "" : node.Parent.Text, node.Parent == null ? "" : Convert.ToString(node.Parent.Tag), sb.ToString()); } } } ★程序运行后,点击“查看” 按钮结果截图: 选中TreeView的一个节点,提示框将提示相应的信息:
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服