⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmcountrycity.cs

📁 Winform_OnlineTraning 我们培训机构的在线培训部分
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Example_2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmCountryCity : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.TreeView tvwCountryCity;
		private System.Windows.Forms.ImageList imgImages;
		private System.Windows.Forms.Label lblCurrentItem;
		private System.ComponentModel.IContainer components;

		public frmCountryCity()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmCountryCity));
			this.tvwCountryCity = new System.Windows.Forms.TreeView();
			this.imgImages = new System.Windows.Forms.ImageList(this.components);
			this.btnExit = new System.Windows.Forms.Button();
			this.lblCurrentItem = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// tvwCountryCity
			// 
			this.tvwCountryCity.ImageList = this.imgImages;
			this.tvwCountryCity.Location = new System.Drawing.Point(0, 0);
			this.tvwCountryCity.Name = "tvwCountryCity";
			this.tvwCountryCity.Size = new System.Drawing.Size(280, 216);
			this.tvwCountryCity.TabIndex = 0;
			this.tvwCountryCity.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvwCountryCity_AfterSelect);
			// 
			// imgImages
			// 
			this.imgImages.ImageSize = new System.Drawing.Size(16, 16);
			this.imgImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgImages.ImageStream")));
			this.imgImages.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(208, 256);
			this.btnExit.Name = "btnExit";
			this.btnExit.TabIndex = 1;
			this.btnExit.Text = "退出(&X)";
			// 
			// lblCurrentItem
			// 
			this.lblCurrentItem.Location = new System.Drawing.Point(8, 224);
			this.lblCurrentItem.Name = "lblCurrentItem";
			this.lblCurrentItem.Size = new System.Drawing.Size(272, 23);
			this.lblCurrentItem.TabIndex = 2;
			// 
			// frmCountryCity
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(288, 285);
			this.Controls.Add(this.lblCurrentItem);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.tvwCountryCity);
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Name = "frmCountryCity";
			this.Text = "国家和城市";
			this.Load += new System.EventHandler(this.frmCountryCity_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmCountryCity());
		}

		private void frmCountryCity_Load(object sender, System.EventArgs e)
		{
			TreeNode objRootNode = tvwCountryCity.Nodes.Add("USA");
			objRootNode.ImageIndex =0 ;

			// Create the Child nodes for the root
			TreeNode objStateNewYork = objRootNode.Nodes.Add("New York");
			objStateNewYork.ImageIndex =1 ;
			TreeNode objStateMichigan = objRootNode.Nodes.Add("Michigan");
			objStateMichigan.ImageIndex =1 ;
			TreeNode objStateCalifornia = objRootNode.Nodes.Add("California");
			objStateCalifornia.ImageIndex =1 ;

			// Create siblings nodes for the Child nodes 
			TreeNode objChild = objStateNewYork.Nodes.Add("Rochester");
			objChild.ImageIndex = 2 ;
			objChild =objStateNewYork.Nodes.Add("Albany");
			objChild.ImageIndex = 2 ;

			objChild = objStateMichigan.Nodes.Add("Detroit");
			objChild.ImageIndex = 2 ;
			objChild =objStateMichigan.Nodes.Add("Ann Arbor");
			objChild.ImageIndex = 2 ;
			
			objChild = objStateCalifornia.Nodes.Add("Los Angeles");
			objChild.ImageIndex = 2 ;
			objChild = objStateCalifornia.Nodes.Add("San Fransisco");
			objChild.ImageIndex = 2 ;
			

		}

		private void tvwCountryCity_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			this.lblCurrentItem.Text = this.tvwCountryCity.SelectedNode.Text;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -