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

📄 form1.cs

📁 c#程序部分代码我没有用过是我的老师给我的用于arcGIS engine 开发的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace cs_nineplay
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.Button button9;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Button btnEnd;
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Button button10;
		private System.Windows.Forms.Button button11;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Label lblTime;
		private System.Windows.Forms.Label lblCount;
		private System.Windows.Forms.Timer tmrTime;
		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();
			this.label1 = new System.Windows.Forms.Label();
			this.lblTime = new System.Windows.Forms.Label();
			this.lblCount = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.button9 = new System.Windows.Forms.Button();
			this.button8 = new System.Windows.Forms.Button();
			this.button5 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.btnEnd = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.tmrTime = new System.Windows.Forms.Timer(this.components);
			this.button10 = new System.Windows.Forms.Button();
			this.button11 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.label1.Font = new System.Drawing.Font("宋体", 24F);
			this.label1.Location = new System.Drawing.Point(24, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(248, 32);
			this.label1.TabIndex = 0;
			this.label1.Text = "九宫格益智游戏";
			// 
			// lblTime
			// 
			this.lblTime.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.lblTime.Font = new System.Drawing.Font("宋体", 14F);
			this.lblTime.Location = new System.Drawing.Point(176, 96);
			this.lblTime.Name = "lblTime";
			this.lblTime.TabIndex = 1;
			this.lblTime.Text = "秒数:0秒";
			// 
			// lblCount
			// 
			this.lblCount.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.lblCount.Font = new System.Drawing.Font("宋体", 14F);
			this.lblCount.Location = new System.Drawing.Point(176, 136);
			this.lblCount.Name = "lblCount";
			this.lblCount.TabIndex = 2;
			this.lblCount.Text = "次数:0次";
			// 
			// button1
			// 
			this.button1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button1.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.Location = new System.Drawing.Point(32, 72);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(40, 40);
			this.button1.TabIndex = 3;
			this.button1.Text = "1";
			// 
			// button6
			// 
			this.button6.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button6.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button6.Location = new System.Drawing.Point(112, 112);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(40, 40);
			this.button6.TabIndex = 5;
			this.button6.Text = "6";
			// 
			// button9
			// 
			this.button9.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button9.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button9.Location = new System.Drawing.Point(112, 152);
			this.button9.Name = "button9";
			this.button9.Size = new System.Drawing.Size(40, 40);
			this.button9.TabIndex = 6;
			this.button9.Text = "9";
			// 
			// button8
			// 
			this.button8.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button8.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button8.Location = new System.Drawing.Point(72, 152);
			this.button8.Name = "button8";
			this.button8.Size = new System.Drawing.Size(40, 40);
			this.button8.TabIndex = 7;
			this.button8.Text = "8";
			// 
			// button5
			// 
			this.button5.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button5.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button5.Location = new System.Drawing.Point(72, 112);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(40, 40);
			this.button5.TabIndex = 8;
			this.button5.Text = "5";
			// 
			// button2
			// 
			this.button2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button2.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button2.Location = new System.Drawing.Point(72, 72);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(40, 40);
			this.button2.TabIndex = 9;
			this.button2.Text = "2";
			// 
			// button7
			// 
			this.button7.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button7.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button7.Location = new System.Drawing.Point(32, 152);
			this.button7.Name = "button7";
			this.button7.Size = new System.Drawing.Size(40, 40);
			this.button7.TabIndex = 10;
			this.button7.Text = "7";
			// 
			// button4
			// 
			this.button4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button4.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button4.Location = new System.Drawing.Point(32, 112);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(40, 40);
			this.button4.TabIndex = 11;
			this.button4.Text = "4";
			// 
			// btnEnd
			// 
			this.btnEnd.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.btnEnd.Font = new System.Drawing.Font("宋体", 14F);
			this.btnEnd.Location = new System.Drawing.Point(104, 208);
			this.btnEnd.Name = "btnEnd";
			this.btnEnd.Size = new System.Drawing.Size(56, 32);
			this.btnEnd.TabIndex = 12;
			this.btnEnd.Text = "结束";
			this.btnEnd.Click += new System.EventHandler(this.btnEnd_Click);
			// 
			// btnStart
			// 
			this.btnStart.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.btnStart.Font = new System.Drawing.Font("宋体", 14F);
			this.btnStart.Location = new System.Drawing.Point(32, 208);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(56, 32);
			this.btnStart.TabIndex = 13;
			this.btnStart.Text = "开始";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// tmrTime
			// 
			this.tmrTime.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// button10
			// 
			this.button10.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button10.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button10.Location = new System.Drawing.Point(40, 112);
			this.button10.Name = "button10";
			this.button10.Size = new System.Drawing.Size(40, 40);
			this.button10.TabIndex = 11;
			this.button10.Text = "4";
			this.button10.Click += new System.EventHandler(this.Button_Click);
			// 
			// button11
			// 
			this.button11.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button11.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button11.Location = new System.Drawing.Point(80, 112);
			this.button11.Name = "button11";
			this.button11.Size = new System.Drawing.Size(40, 40);
			this.button11.TabIndex = 8;
			this.button11.Text = "5";
			this.button11.Click += new System.EventHandler(this.Button_Click);
			// 
			// button3
			// 
			this.button3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.button3.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button3.Location = new System.Drawing.Point(112, 72);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(40, 40);
			this.button3.TabIndex = 4;
			this.button3.Text = "3";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(296, 270);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnStart,
																		  this.btnEnd,
																		  this.button4,
																		  this.button7,
																		  this.button2,
																		  this.button5,
																		  this.button8,
																		  this.button9,
																		  this.button6,
																		  this.button1,
																		  this.lblCount,
																		  this.lblTime,
																		  this.label1,
																		  this.button10,
																		  this.button11,
																		  this.button3});
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		Color OnColor = Color.Coral;
		Color OffColor = Color.Yellow;
		int seconds;
		int count1;

		int[,] ChangeCells = {	{-1, -1, -1, -1, -1}, 
				{1, 2, 4, 5, -1}, 
				{2, 1, 3, -1, -1}, 
				{3, 2, 5, 6, -1}, 
				{4, 1, 7, -1, -1}, 
				{5, 2, 4, 6, 8}, 
				{6, 3, 9, -1, -1}, 
				{7, 4, 5, 8, -1}, 
				{8, 7, 9, -1, -1}, 
				{9, 5, 6, 8, -1} 
							 };

		Button[] Buttons = new Button[10];

		private void Button_Click(object sender, System.EventArgs e)
		{
			Button btnHit = (Button)sender;
			int No = int.Parse(btnHit.Text);
			for(int i=0;i<5;i++)
			{
				int X = ChangeCells[No, i];
				if (X != -1)
				{
					if (Buttons[X].BackColor.ToArgb() == OffColor.ToArgb())
						Buttons[X].BackColor = OnColor;
					else
						Buttons[X].BackColor = OffColor;
				}
			}
			count1 += 1;
			lblCount.Text = "次数 : " + count1.ToString() + "次";
			int sum = 0;
			for(int i=1;i<=9;i++)
			{
				if (Buttons[i].BackColor.ToArgb() == OnColor.ToArgb())
					sum += 1;
			}
			if (sum == 8 && Buttons[5].BackColor.ToArgb() == OffColor.ToArgb())
			{
				btnStart.Enabled = true;
				btnEnd.Enabled = false;
				tmrTime.Enabled = false;
				MessageBox.Show("恭喜! 过关....");
				for(int i=1;i<=9;i++)
					Buttons[i].Enabled = false;
			}
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			btnStart.Enabled = true;
			btnEnd.Enabled = false;
			button1.Click += new EventHandler(Button_Click);
			button2.Click += new EventHandler(Button_Click);
			button3.Click += new EventHandler(Button_Click);
			button4.Click += new EventHandler(Button_Click);
			button5.Click += new EventHandler(Button_Click);
			button6.Click += new EventHandler(Button_Click);
			button7.Click += new EventHandler(Button_Click);
			button8.Click += new EventHandler(Button_Click);
			button9.Click += new EventHandler(Button_Click);
			Buttons[1] = button1;
			Buttons[2] = button2;
			Buttons[3] = button3;
			Buttons[4] = button4;
			Buttons[5] = button5;
			Buttons[6] = button6;
			Buttons[7] = button7;
			Buttons[8] = button8;
			Buttons[9] = button9;
			for(int i=1;i<=9;i++)
				Buttons[i].Enabled = false;

		}


		private void timer1_Tick(object sender, System.EventArgs e)
		{
			seconds += 1;
			lblTime.Text = "秒数: " + seconds.ToString() + " 秒";
  
		}

		private void btnEnd_Click(object sender, System.EventArgs e)
		{
		   Application.Exit();
		}

		private void btnStart_Click(object sender, System.EventArgs e)
		{
			count1 = 0;
			seconds = 0;
			lblCount.Text = "次数 : " + count1.ToString() + "次";
			lblTime.Text = "秒数 : " + seconds.ToString() + "次";
			Random r = new Random();
			for(int i=1;i<=9;i++)
			{
				Buttons[i].Enabled = true;
				if (r.Next(1,10) > 5)
					Buttons[i].BackColor = OnColor;
				else
					Buttons[i].BackColor = OffColor;
			}
			seconds = 0;
			tmrTime.Enabled = true;
			btnStart.Enabled = false;
			btnEnd.Enabled = true;

		}

		
	}
}

⌨️ 快捷键说明

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