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

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WinAppComboBox01
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		int yearStart;
		int yearEnd;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ListBox lstOut;
		private System.Windows.Forms.ComboBox cboStart;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cboEnd;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Button btnClear;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		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 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.label1 = new System.Windows.Forms.Label();
            this.lstOut = new System.Windows.Forms.ListBox();
            this.cboStart = new System.Windows.Forms.ComboBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.cboEnd = new System.Windows.Forms.ComboBox();
            this.btnStart = new System.Windows.Forms.Button();
            this.btnClear = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(11, 21);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(165, 41);
            this.label1.TabIndex = 0;
            this.label1.Text = "显示范围内所有闰年";
            this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
            // 
            // lstOut
            // 
            this.lstOut.ItemHeight = 15;
            this.lstOut.Location = new System.Drawing.Point(21, 72);
            this.lstOut.Name = "lstOut";
            this.lstOut.Size = new System.Drawing.Size(160, 229);
            this.lstOut.TabIndex = 1;
            // 
            // cboStart
            // 
            this.cboStart.Items.AddRange(new object[] {
            "1955",
            "1960",
            "1965",
            "1970",
            "1975",
            "1980"});
            this.cboStart.Location = new System.Drawing.Point(203, 72);
            this.cboStart.Name = "cboStart";
            this.cboStart.Size = new System.Drawing.Size(161, 23);
            this.cboStart.TabIndex = 2;
            this.cboStart.SelectedIndexChanged += new System.EventHandler(this.cboStart_SelectedIndexChanged);
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(203, 31);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(133, 29);
            this.label2.TabIndex = 3;
            this.label2.Text = "选择起始年份:";
            this.label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(203, 103);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(133, 29);
            this.label3.TabIndex = 4;
            this.label3.Text = "选择终止年份:";
            this.label3.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
            // 
            // cboEnd
            // 
            this.cboEnd.Items.AddRange(new object[] {
            "1975",
            "1980",
            "1985",
            "1990",
            "1995",
            "2000",
            "2005"});
            this.cboEnd.Location = new System.Drawing.Point(203, 144);
            this.cboEnd.Name = "cboEnd";
            this.cboEnd.Size = new System.Drawing.Size(161, 23);
            this.cboEnd.TabIndex = 5;
            // 
            // btnStart
            // 
            this.btnStart.Location = new System.Drawing.Point(224, 206);
            this.btnStart.Name = "btnStart";
            this.btnStart.Size = new System.Drawing.Size(100, 29);
            this.btnStart.TabIndex = 6;
            this.btnStart.Text = "开始";
            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
            // 
            // btnClear
            // 
            this.btnClear.Location = new System.Drawing.Point(224, 257);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new System.Drawing.Size(100, 30);
            this.btnClear.TabIndex = 7;
            this.btnClear.Text = "清除";
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
            this.ClientSize = new System.Drawing.Size(389, 341);
            this.Controls.Add(this.btnClear);
            this.Controls.Add(this.btnStart);
            this.Controls.Add(this.cboEnd);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.cboStart);
            this.Controls.Add(this.lstOut);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "判断闰年";
            this.ResumeLayout(false);

		}
		#endregion

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

		private void btnStart_Click(object sender, System.EventArgs e)
		{
			if(cboStart.Text==""||cboEnd.Text=="")
			{return ;}
						
			yearStart=int.Parse(cboStart.Text);
			yearEnd=int.Parse(cboEnd.Text);
			//lstOut.Items.Add(yearStart.ToString( ));
			//lstOut.Items.Add(yearEnd.ToString ( ));
			if(yearStart>yearEnd)
				return;
			//lstOut.Items.Add(cboStart.SelectedIndex);
			//lstOut.Items.Add(cboStart.SelectedItem);
			//lstOut.Items.Add(cboEnd.SelectedIndex);
			//lstOut.Items.Add(cboEnd.SelectedItem);
			lstOut.Items.Clear( );
			for(int i=yearStart;i<=yearEnd;i++)
				if(i%4==0&&i%100!=0||i%400==0)
					lstOut.Items.Add(i);
		}

		private void btnClear_Click(object sender, System.EventArgs e)
		{
			lstOut.Items.Clear( );
		}

		private void cboStart_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//for(int i=0;i<cboStart.Items.Count;i++)
			//	if(
			//cboStart.Items.Add(cboStart.SelectedItem);
		}
	}
}

⌨️ 快捷键说明

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