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

📄 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_Tank
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox picTankU;
		private System.Windows.Forms.PictureBox picTankR;
		private System.Windows.Forms.PictureBox picTankL;
		private System.Windows.Forms.PictureBox picTankD;
		private System.Windows.Forms.Label lblX;
		private System.Windows.Forms.Label lblMsg;
		private System.Windows.Forms.Label lblY;
		private System.Windows.Forms.PictureBox picTank;
		/// <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 Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.picTankU = new System.Windows.Forms.PictureBox();
			this.picTankR = new System.Windows.Forms.PictureBox();
			this.picTankL = new System.Windows.Forms.PictureBox();
			this.picTankD = new System.Windows.Forms.PictureBox();
			this.lblX = new System.Windows.Forms.Label();
			this.lblMsg = new System.Windows.Forms.Label();
			this.lblY = new System.Windows.Forms.Label();
			this.picTank = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// picTankU
			// 
			this.picTankU.Image = ((System.Drawing.Bitmap)(resources.GetObject("picTankU.Image")));
			this.picTankU.Location = new System.Drawing.Point(16, 16);
			this.picTankU.Name = "picTankU";
			this.picTankU.Size = new System.Drawing.Size(66, 73);
			this.picTankU.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
			this.picTankU.TabIndex = 0;
			this.picTankU.TabStop = false;
			// 
			// picTankR
			// 
			this.picTankR.Image = ((System.Drawing.Bitmap)(resources.GetObject("picTankR.Image")));
			this.picTankR.Location = new System.Drawing.Point(110, 97);
			this.picTankR.Name = "picTankR";
			this.picTankR.Size = new System.Drawing.Size(71, 67);
			this.picTankR.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
			this.picTankR.TabIndex = 1;
			this.picTankR.TabStop = false;
			// 
			// picTankL
			// 
			this.picTankL.Image = ((System.Drawing.Bitmap)(resources.GetObject("picTankL.Image")));
			this.picTankL.Location = new System.Drawing.Point(16, 104);
			this.picTankL.Name = "picTankL";
			this.picTankL.Size = new System.Drawing.Size(76, 64);
			this.picTankL.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
			this.picTankL.TabIndex = 2;
			this.picTankL.TabStop = false;
			// 
			// picTankD
			// 
			this.picTankD.Image = ((System.Drawing.Bitmap)(resources.GetObject("picTankD.Image")));
			this.picTankD.Location = new System.Drawing.Point(112, 8);
			this.picTankD.Name = "picTankD";
			this.picTankD.Size = new System.Drawing.Size(65, 71);
			this.picTankD.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
			this.picTankD.TabIndex = 3;
			this.picTankD.TabStop = false;
			// 
			// lblX
			// 
			this.lblX.Location = new System.Drawing.Point(8, 184);
			this.lblX.Name = "lblX";
			this.lblX.TabIndex = 4;
			this.lblX.Text = "label1";
			// 
			// lblMsg
			// 
			this.lblMsg.Location = new System.Drawing.Point(8, 248);
			this.lblMsg.Name = "lblMsg";
			this.lblMsg.Size = new System.Drawing.Size(184, 23);
			this.lblMsg.TabIndex = 5;
			this.lblMsg.Text = "label2";
			// 
			// lblY
			// 
			this.lblY.Location = new System.Drawing.Point(8, 216);
			this.lblY.Name = "lblY";
			this.lblY.TabIndex = 6;
			this.lblY.Text = "label3";
			// 
			// picTank
			// 
			this.picTank.Location = new System.Drawing.Point(224, 208);
			this.picTank.Name = "picTank";
			this.picTank.Size = new System.Drawing.Size(72, 72);
			this.picTank.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
			this.picTank.TabIndex = 7;
			this.picTank.TabStop = false;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.ClientSize = new System.Drawing.Size(320, 294);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.picTank,
																		  this.lblY,
																		  this.lblMsg,
																		  this.lblX,
																		  this.picTankD,
																		  this.picTankL,
																		  this.picTankR,
																		  this.picTankU});
			this.Name = "Form1";
			this.Text = "Form1";
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
			this.Load += new System.EventHandler(this.Form1_Load);
			this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void Form1_Load(object sender, System.EventArgs e)
		{
			lblX.Text = "X坐标:" + picTank.Top;
			lblY.Text = "Y坐标:" + picTank.Left;
			lblMsg.Text = "请按上下左右键控制坦克!";
				picTank.Image = picTankU.Image;
			picTankU.Visible = false;
			picTankD.Visible = false;
			picTankL.Visible = false;
			picTankR.Visible = false;		

		}

		private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			switch(e.KeyCode)
			{
				case Keys.Up:
					picTank.Image = picTankU.Image;
					if ((picTank.Top + picTank.Height) <= 0 )
						picTank.Top = this.Height;
					else
						picTank.Top -= 10;
					break;
				case Keys.Down:
					picTank.Image = picTankD.Image;
					if (picTank.Top >= this.Height)
						picTank.Top = 0 - picTank.Height;
					else
						picTank.Top += 10;
					break;
				case Keys.Left:
					picTank.Image = picTankL.Image;
					if (picTank.Width + picTank.Left <= 0)
						picTank.Left = this.Width;
					else
						picTank.Left -= 10;
					break;
				case Keys.Right:
					picTank.Image = picTankR.Image;
					if (picTank.Left >= this.Width)
						picTank.Left = 0 - picTank.Width;
					else
						picTank.Left += 10;
					break;
			}
			lblX.Text = "X坐标:" + picTank.Top;
			lblY.Text = "Y坐标:" + picTank.Left;
			lblMsg.Text = "现在按下" + e.KeyCode.ToString() +
				"键,键盘值为" + e.KeyValue.ToString() + "!!";

		}

		private void Form1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
		    lblMsg.Text = "请按上下左右键控制坦克!";
		}
	}
}

⌨️ 快捷键说明

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