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

📄 form1.cs

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

namespace testComboBoxApp
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox cbBoxYear;
		private System.Windows.Forms.ComboBox cbBoxMonth;
		private System.Windows.Forms.ComboBox cbBoxDay;
		private System.Windows.Forms.ComboBox cbBoxName;
		private System.Windows.Forms.Button btnConfirm;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			cbBoxYear.BeginUpdate();
			for (int i = 1900; i <=2002; i++) 
			{
				cbBoxYear.Items.Add( i.ToString());
			}
			cbBoxYear.EndUpdate();
			cbBoxMonth.BeginUpdate();
			for (int i = 1; i <=12; i++) 
			{
				cbBoxMonth.Items.Add( i.ToString());
			}
			cbBoxMonth.EndUpdate();
			cbBoxDay.BeginUpdate();
			for (int i = 1; i <= 31; i++) 
			{
				cbBoxDay.Items.Add( i.ToString());
			}
			cbBoxDay.EndUpdate();

		}

		/// <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.label1 = new System.Windows.Forms.Label();
			this.cbBoxYear = new System.Windows.Forms.ComboBox();
			this.cbBoxMonth = new System.Windows.Forms.ComboBox();
			this.cbBoxDay = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.cbBoxName = new System.Windows.Forms.ComboBox();
			this.btnConfirm = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 80);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "您的生日:";
			// 
			// cbBoxYear
			// 
			this.cbBoxYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbBoxYear.Location = new System.Drawing.Point(112, 80);
			this.cbBoxYear.Name = "cbBoxYear";
			this.cbBoxYear.Size = new System.Drawing.Size(56, 20);
			this.cbBoxYear.TabIndex = 1;
			// 
			// cbBoxMonth
			// 
			this.cbBoxMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbBoxMonth.Location = new System.Drawing.Point(176, 80);
			this.cbBoxMonth.Name = "cbBoxMonth";
			this.cbBoxMonth.Size = new System.Drawing.Size(56, 20);
			this.cbBoxMonth.TabIndex = 2;
			// 
			// cbBoxDay
			// 
			this.cbBoxDay.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cbBoxDay.Location = new System.Drawing.Point(240, 80);
			this.cbBoxDay.Name = "cbBoxDay";
			this.cbBoxDay.Size = new System.Drawing.Size(48, 20);
			this.cbBoxDay.TabIndex = 3;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 16);
			this.label2.Name = "label2";
			this.label2.TabIndex = 4;
			this.label2.Text = "您的姓名:";
			// 
			// cbBoxName
			// 
			this.cbBoxName.Items.AddRange(new object[] {
														   "李老大",
														   "李老二",
														   "刘老三",
														   "高老四",
														   "冯老五"});
			this.cbBoxName.Location = new System.Drawing.Point(128, 16);
			this.cbBoxName.Name = "cbBoxName";
			this.cbBoxName.Size = new System.Drawing.Size(144, 20);
			this.cbBoxName.TabIndex = 5;
			// 
			// btnConfirm
			// 
			this.btnConfirm.Location = new System.Drawing.Point(208, 136);
			this.btnConfirm.Name = "btnConfirm";
			this.btnConfirm.Size = new System.Drawing.Size(80, 24);
			this.btnConfirm.TabIndex = 6;
			this.btnConfirm.Text = "确认";
			this.btnConfirm.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(304, 173);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnConfirm,
																		  this.cbBoxName,
																		  this.label2,
																		  this.cbBoxDay,
																		  this.cbBoxMonth,
																		  this.cbBoxYear,
																		  this.label1});
			this.Name = "Form1";
			this.Text = "testComboBox";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void Form1_Load(object sender, System.EventArgs e)
		{

		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			int FindIndex;
			string strMsg = " You are: ";
			FindIndex = cbBoxName.FindStringExact (cbBoxName.Text );
			if (FindIndex < 0)
			{
				cbBoxName.Items.Add (cbBoxName.Text);
				strMsg += cbBoxName.Text;
			}
			else 
			{
				strMsg += cbBoxName.SelectedItem.ToString ();
			}
			if ((cbBoxYear.SelectedIndex >= 0)&&(cbBoxMonth.SelectedIndex >=0)&&(cbBoxDay.SelectedIndex >=0))
			{
				strMsg +="Your birthday is: " + cbBoxYear.SelectedItem.ToString() +"/" + cbBoxMonth.SelectedItem.ToString() +"/"
					+ cbBoxDay.SelectedItem.ToString() ;
			}
			MessageBox.Show (strMsg);
         }
	}
}

⌨️ 快捷键说明

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