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

📄 elevator.cs

📁 设计一个电梯模拟系统。主要用于实现
💻 CS
📖 第 1 页 / 共 4 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Timers;

namespace Elevator
{
	//Directs of the elevators, UP means moving upward
	//DOWN moving downwards and HALT a free moving state
	enum Direct{UP = -1, HALT, DOWN};
	public class Elevator : System.Windows.Forms.Form
	{
		//Automatically generated code
		private System.Windows.Forms.GroupBox elevator1;
		private System.Windows.Forms.Button elevatorButton11;
		private System.Windows.Forms.Button elevatorButton12;
		private System.Windows.Forms.Button elevatorButton13;
		private System.Windows.Forms.Button elevatorButton14;
		private System.Windows.Forms.TextBox elevatorTextBox1;

		private System.Windows.Forms.GroupBox elevator2;
		private System.Windows.Forms.Button elevatorButton21;
		private System.Windows.Forms.Button elevatorButton22;
		private System.Windows.Forms.Button elevatorButton23;
		private System.Windows.Forms.Button elevatorButton24;
		private System.Windows.Forms.TextBox elevatorTextBox2;

		private System.Windows.Forms.Button outButton12;
		private System.Windows.Forms.Button outButton14;
		private System.Windows.Forms.Button inButton13;
		private System.Windows.Forms.Button inButton11;
		private System.Windows.Forms.Button upButton1;
		private System.Windows.Forms.Button floor1;

		private System.Windows.Forms.Button outButton34;
		private System.Windows.Forms.Button inButton33;
		private System.Windows.Forms.Button outButton32;
		private System.Windows.Forms.Button inButton31;
		private System.Windows.Forms.Button downButton3;
		private System.Windows.Forms.Button upButton3;
		private System.Windows.Forms.Button floor3;

		private System.Windows.Forms.Button outButton42;
		private System.Windows.Forms.Button outButton44;
		private System.Windows.Forms.Button inButton43;
		private System.Windows.Forms.Button inButton41;
		private System.Windows.Forms.Button downButton4;
		private System.Windows.Forms.Button floor4;

		private System.Windows.Forms.Button outButton22;
		private System.Windows.Forms.Button outButton24;
		private System.Windows.Forms.Button inButton23;
		private System.Windows.Forms.Button inButton21;
		private System.Windows.Forms.Button upButton2;
		private System.Windows.Forms.Button floor2;
		private System.Windows.Forms.Button downButton2;

		private System.Windows.Forms.Timer timerControl;
		private System.ComponentModel.IContainer components;
		
		//User-defined codes	
		private int passengerE1;										//People in elevator1
		private int passengerE2;										//People in elevator2
		private int suspendTime1 = 0;									//Delay elevator1's ascending or descending
		private int suspendTime2 = 0;									//Delay elevator1's ascending or descending
		private int directE1 = (int)Direct.HALT;						//Elevator1's moving direction
		private int directE2 = (int)Direct.HALT;						//Elevator2's moving direction
		private int stateE1 = 1;										//Elevator1's now in which floor
		private int stateE2 = 1;										//Elevator2's now in which floor
		private int [] destination1 = new int [] {0,0,0,0,0};		//Elevator1's destination
		private int [] destination2 = new int [] {0,0,0,0,0};		//Elevator2's destination
		//Unhandled requests of upButtons or downButtons, and false means the corresponding event
		//Has been handled, otherwise unhandled.
		private bool [,] unhandled = {{false,false,false,false,false},
										{false,false,false,false,false}};

		public Elevator()
		{
			InitializeComponent();
		}

		/// <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();
			this.elevator1 = new System.Windows.Forms.GroupBox();
			this.elevatorButton14 = new System.Windows.Forms.Button();
			this.elevatorButton13 = new System.Windows.Forms.Button();
			this.elevatorButton12 = new System.Windows.Forms.Button();
			this.elevatorButton11 = new System.Windows.Forms.Button();
			this.elevatorTextBox1 = new System.Windows.Forms.TextBox();
			this.elevator2 = new System.Windows.Forms.GroupBox();
			this.elevatorButton21 = new System.Windows.Forms.Button();
			this.elevatorButton22 = new System.Windows.Forms.Button();
			this.elevatorButton23 = new System.Windows.Forms.Button();
			this.elevatorButton24 = new System.Windows.Forms.Button();
			this.elevatorTextBox2 = new System.Windows.Forms.TextBox();
			this.outButton12 = new System.Windows.Forms.Button();
			this.outButton14 = new System.Windows.Forms.Button();
			this.inButton13 = new System.Windows.Forms.Button();
			this.inButton11 = new System.Windows.Forms.Button();
			this.upButton1 = new System.Windows.Forms.Button();
			this.floor1 = new System.Windows.Forms.Button();
			this.outButton34 = new System.Windows.Forms.Button();
			this.inButton33 = new System.Windows.Forms.Button();
			this.inButton31 = new System.Windows.Forms.Button();
			this.downButton3 = new System.Windows.Forms.Button();
			this.upButton3 = new System.Windows.Forms.Button();
			this.floor3 = new System.Windows.Forms.Button();
			this.outButton42 = new System.Windows.Forms.Button();
			this.outButton44 = new System.Windows.Forms.Button();
			this.inButton43 = new System.Windows.Forms.Button();
			this.inButton41 = new System.Windows.Forms.Button();
			this.downButton4 = new System.Windows.Forms.Button();
			this.floor4 = new System.Windows.Forms.Button();
			this.outButton22 = new System.Windows.Forms.Button();
			this.outButton24 = new System.Windows.Forms.Button();
			this.inButton23 = new System.Windows.Forms.Button();
			this.inButton21 = new System.Windows.Forms.Button();
			this.upButton2 = new System.Windows.Forms.Button();
			this.floor2 = new System.Windows.Forms.Button();
			this.downButton2 = new System.Windows.Forms.Button();
			this.outButton32 = new System.Windows.Forms.Button();
			this.timerControl = new System.Windows.Forms.Timer(this.components);
			this.elevator1.SuspendLayout();
			this.elevator2.SuspendLayout();
			this.SuspendLayout();
			// 
			// elevator1
			// 
			this.elevator1.BackColor = System.Drawing.Color.LightSeaGreen;
			this.elevator1.Controls.Add(this.elevatorButton14);
			this.elevator1.Controls.Add(this.elevatorButton13);
			this.elevator1.Controls.Add(this.elevatorButton12);
			this.elevator1.Controls.Add(this.elevatorButton11);
			this.elevator1.Controls.Add(this.elevatorTextBox1);
			this.elevator1.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.elevator1.Location = new System.Drawing.Point(16, 400);
			this.elevator1.Name = "elevator1";
			this.elevator1.Size = new System.Drawing.Size(80, 112);
			this.elevator1.TabIndex = 0;
			this.elevator1.TabStop = false;
			this.elevator1.Text = "Elevator1";
			// 
			// elevatorButton14
			// 
			this.elevatorButton14.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.elevatorButton14.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton14.Enabled = false;
			this.elevatorButton14.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton14.Location = new System.Drawing.Point(56, 19);
			this.elevatorButton14.Name = "elevatorButton14";
			this.elevatorButton14.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton14.TabIndex = 3;
			this.elevatorButton14.Text = "4";
			this.elevatorButton14.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorButton13
			// 
			this.elevatorButton13.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.elevatorButton13.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton13.Enabled = false;
			this.elevatorButton13.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton13.Location = new System.Drawing.Point(56, 42);
			this.elevatorButton13.Name = "elevatorButton13";
			this.elevatorButton13.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton13.TabIndex = 2;
			this.elevatorButton13.Text = "3";
			this.elevatorButton13.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorButton12
			// 
			this.elevatorButton12.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.elevatorButton12.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton12.Enabled = false;
			this.elevatorButton12.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton12.Location = new System.Drawing.Point(56, 65);
			this.elevatorButton12.Name = "elevatorButton12";
			this.elevatorButton12.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton12.TabIndex = 1;
			this.elevatorButton12.Text = "2";
			this.elevatorButton12.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorButton11
			// 
			this.elevatorButton11.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.elevatorButton11.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton11.Enabled = false;
			this.elevatorButton11.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton11.Location = new System.Drawing.Point(56, 88);
			this.elevatorButton11.Name = "elevatorButton11";
			this.elevatorButton11.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton11.TabIndex = 0;
			this.elevatorButton11.Text = "1";
			this.elevatorButton11.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorTextBox1
			// 
			this.elevatorTextBox1.Location = new System.Drawing.Point(8, 56);
			this.elevatorTextBox1.Name = "elevatorTextBox1";
			this.elevatorTextBox1.ReadOnly = true;
			this.elevatorTextBox1.Size = new System.Drawing.Size(24, 21);
			this.elevatorTextBox1.TabIndex = 1;
			this.elevatorTextBox1.Text = "0";
			// 
			// elevator2
			// 
			this.elevator2.BackColor = System.Drawing.Color.LightSeaGreen;
			this.elevator2.Controls.Add(this.elevatorButton21);
			this.elevator2.Controls.Add(this.elevatorButton22);
			this.elevator2.Controls.Add(this.elevatorButton23);
			this.elevator2.Controls.Add(this.elevatorButton24);
			this.elevator2.Controls.Add(this.elevatorTextBox2);
			this.elevator2.Font = new System.Drawing.Font("SimSun", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.elevator2.Location = new System.Drawing.Point(256, 400);
			this.elevator2.Name = "elevator2";
			this.elevator2.Size = new System.Drawing.Size(80, 112);
			this.elevator2.TabIndex = 1;
			this.elevator2.TabStop = false;
			this.elevator2.Text = "Elevator2";
			// 
			// elevatorButton21
			// 
			this.elevatorButton21.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.elevatorButton21.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton21.Enabled = false;
			this.elevatorButton21.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton21.Location = new System.Drawing.Point(0, 88);
			this.elevatorButton21.Name = "elevatorButton21";
			this.elevatorButton21.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton21.TabIndex = 0;
			this.elevatorButton21.Text = "1";
			this.elevatorButton21.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorButton22
			// 
			this.elevatorButton22.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.elevatorButton22.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton22.Enabled = false;
			this.elevatorButton22.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton22.Location = new System.Drawing.Point(0, 65);
			this.elevatorButton22.Name = "elevatorButton22";
			this.elevatorButton22.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton22.TabIndex = 1;
			this.elevatorButton22.Text = "2";
			this.elevatorButton22.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorButton23
			// 
			this.elevatorButton23.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.elevatorButton23.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton23.Enabled = false;
			this.elevatorButton23.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton23.Location = new System.Drawing.Point(0, 42);
			this.elevatorButton23.Name = "elevatorButton23";
			this.elevatorButton23.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton23.TabIndex = 2;
			this.elevatorButton23.Text = "3";
			this.elevatorButton23.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorButton24
			// 
			this.elevatorButton24.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.elevatorButton24.BackColor = System.Drawing.SystemColors.Control;
			this.elevatorButton24.Enabled = false;
			this.elevatorButton24.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.elevatorButton24.Location = new System.Drawing.Point(0, 19);
			this.elevatorButton24.Name = "elevatorButton24";
			this.elevatorButton24.Size = new System.Drawing.Size(24, 23);
			this.elevatorButton24.TabIndex = 3;
			this.elevatorButton24.Text = "4";
			this.elevatorButton24.Click += new System.EventHandler(this.elevatorButton_Click);
			// 
			// elevatorTextBox2
			// 
			this.elevatorTextBox2.Location = new System.Drawing.Point(40, 48);
			this.elevatorTextBox2.Name = "elevatorTextBox2";
			this.elevatorTextBox2.ReadOnly = true;
			this.elevatorTextBox2.Size = new System.Drawing.Size(24, 21);
			this.elevatorTextBox2.TabIndex = 1;
			this.elevatorTextBox2.Text = "0";
			// 
			// outButton12
			// 
			this.outButton12.BackColor = System.Drawing.SystemColors.Control;
			this.outButton12.Enabled = false;
			this.outButton12.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.outButton12.Location = new System.Drawing.Point(120, 472);
			this.outButton12.Name = "outButton12";
			this.outButton12.Size = new System.Drawing.Size(24, 24);
			this.outButton12.TabIndex = 29;
			this.outButton12.Text = ">";
			this.outButton12.Click += new System.EventHandler(this.pressButton1_Click);
			// 
			// outButton14
			// 
			this.outButton14.BackColor = System.Drawing.SystemColors.Control;
			this.outButton14.Enabled = false;
			this.outButton14.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

⌨️ 快捷键说明

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