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

📄 form1.cs

📁 Csharp实例编程百例.rar
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace testToolBarApp
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ToolBar myToolBar;
		private System.Windows.Forms.ToolBarButton tbBtnNew;
		private System.Windows.Forms.ToolBarButton tbBtnOpen;
		private System.Windows.Forms.ToolBarButton tbBtnExit;
		private System.Windows.Forms.ToolBarButton tbSeparator1;
		private System.Windows.Forms.ToolBarButton tbBtnFunc1;
		private System.Windows.Forms.ToolBarButton tbBtnFunc2;
		private System.Windows.Forms.ImageList ilToolBar;
		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.myToolBar = new System.Windows.Forms.ToolBar();
			this.tbBtnNew = new System.Windows.Forms.ToolBarButton();
			this.tbBtnOpen = new System.Windows.Forms.ToolBarButton();
			this.tbBtnExit = new System.Windows.Forms.ToolBarButton();
			this.tbSeparator1 = new System.Windows.Forms.ToolBarButton();
			this.tbBtnFunc1 = new System.Windows.Forms.ToolBarButton();
			this.tbBtnFunc2 = new System.Windows.Forms.ToolBarButton();
			this.ilToolBar = new System.Windows.Forms.ImageList(this.components);
			this.SuspendLayout();
			// 
			// myToolBar
			// 
			this.myToolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						 this.tbBtnNew,
																						 this.tbBtnOpen,
																						 this.tbBtnExit,
																						 this.tbSeparator1,
																						 this.tbBtnFunc1,
																						 this.tbBtnFunc2});
			this.myToolBar.DropDownArrows = true;
			this.myToolBar.ImageList = this.ilToolBar;
			this.myToolBar.Name = "myToolBar";
			this.myToolBar.ShowToolTips = true;
			this.myToolBar.Size = new System.Drawing.Size(416, 38);
			this.myToolBar.TabIndex = 0;
			this.myToolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.myToolBar_ButtonClick);
			// 
			// tbBtnNew
			// 
			this.tbBtnNew.ImageIndex = 0;
			this.tbBtnNew.Text = "新建";
			this.tbBtnNew.ToolTipText = "新建文件";
			// 
			// tbBtnOpen
			// 
			this.tbBtnOpen.ImageIndex = 1;
			this.tbBtnOpen.Text = "打开";
			this.tbBtnOpen.ToolTipText = "打开文件";
			// 
			// tbBtnExit
			// 
			this.tbBtnExit.ImageIndex = 2;
			this.tbBtnExit.Text = "退出";
			this.tbBtnExit.ToolTipText = "退出程序";
			// 
			// tbSeparator1
			// 
			this.tbSeparator1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbBtnFunc1
			// 
			this.tbBtnFunc1.ImageIndex = 3;
			this.tbBtnFunc1.Text = "功能1";
			this.tbBtnFunc1.ToolTipText = "功能1";
			// 
			// tbBtnFunc2
			// 
			this.tbBtnFunc2.ImageIndex = 4;
			this.tbBtnFunc2.Text = "功能2";
			this.tbBtnFunc2.ToolTipText = "功能2";
			// 
			// ilToolBar
			// 
			this.ilToolBar.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.ilToolBar.ImageSize = new System.Drawing.Size(16, 16);
			this.ilToolBar.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilToolBar.ImageStream")));
			this.ilToolBar.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(416, 317);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.myToolBar});
			this.Name = "Form1";
			this.Text = "testToolBar";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void myToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch (e.Button .ImageIndex )
			{
				case 0:
					MessageBox.Show ("New File");
					break;
				case 1:
					MessageBox.Show ("Open File");
					break;
				case 2:
					this.Close();
					break;
				case 3:
					//call func1
					MessageBox.Show ("Function 1 ");
					break;
				case 4:
					//call func2
					MessageBox.Show ("Function 2");
					break;
				default:
					break;
			}
		}
	}
}

⌨️ 快捷键说明

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