📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace testTreeViewApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnExpand;
private System.Windows.Forms.ImageList ilChinaArea;
private System.Windows.Forms.TreeView tvChinaArea;
private System.Windows.Forms.Button btnShowInfo;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.tvChinaArea = new System.Windows.Forms.TreeView();
this.btnExpand = new System.Windows.Forms.Button();
this.btnShowInfo = new System.Windows.Forms.Button();
this.ilChinaArea = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// tvChinaArea
//
this.tvChinaArea.ImageList = this.ilChinaArea;
this.tvChinaArea.Name = "tvChinaArea";
this.tvChinaArea.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("中国", 0, 0, new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("华北地区", 1, 1, new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("北京市", 2, 2),
new System.Windows.Forms.TreeNode("天津市", 2, 2)}),
new System.Windows.Forms.TreeNode("华东地区", 1, 1, new System.Windows.Forms.TreeNode[] {
new System.Windows.Forms.TreeNode("上海市", 2, 2)}),
new System.Windows.Forms.TreeNode("东北地区", 1, 1)})});
this.tvChinaArea.Size = new System.Drawing.Size(167, 272);
this.tvChinaArea.TabIndex = 0;
//
// btnExpand
//
this.btnExpand.Location = new System.Drawing.Point(176, 176);
this.btnExpand.Name = "btnExpand";
this.btnExpand.TabIndex = 1;
this.btnExpand.Text = "展开节点";
this.btnExpand.Click += new System.EventHandler(this.btnExpand_Click);
//
// btnShowInfo
//
this.btnShowInfo.Location = new System.Drawing.Point(176, 232);
this.btnShowInfo.Name = "btnShowInfo";
this.btnShowInfo.TabIndex = 2;
this.btnShowInfo.Text = "显示信息";
this.btnShowInfo.Click += new System.EventHandler(this.btnShowInfo_Click);
//
// ilChinaArea
//
this.ilChinaArea.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.ilChinaArea.ImageSize = new System.Drawing.Size(16, 16);
this.ilChinaArea.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilChinaArea.ImageStream")));
this.ilChinaArea.TransparentColor = System.Drawing.Color.Transparent;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(264, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnShowInfo,
this.btnExpand,
this.tvChinaArea});
this.Name = "Form1";
this.Text = "testTreeView";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnExpand_Click(object sender, System.EventArgs e)
{
tvChinaArea.ExpandAll ();
}
private void btnShowInfo_Click(object sender, System.EventArgs e)
{
string AreaInfo;
AreaInfo = tvChinaArea.SelectedNode.ToString ();
MessageBox.Show ("You choose" + AreaInfo );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -