using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Threading;namespace 坦克大战0._1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //this.Location = new Point(50, 50);//窗口的位置 //this.DesktopLocation = new Point(50,50); this.Opacity = 1;//设置透明度 this.Text = "坦克大战0.2";//设置标题 this.SetDesktopLocation(60, 60);//窗口位置 this.StartPosition = FormStartPosition.Manual; this.Size = new Size(800, 600); this.AutoSizeMode = AutoSizeMode.GrowAndShrink;//禁止手动调整大小 this.MaximizeBox = false;//使最大化失效 this.BackColor = Color.Orange; //设置背景色 } static int x = 50, y = 50; static int vx = x + 15, vy = y - 15; private void Form1_Paint(object sender, PaintEventArgs e) { Color c = this.BackColor;//获取窗口背景色 Pen a = new Pen(Color.Red);//new画笔 a.Width = 5;//设置画笔宽度 //e.Graphics.DrawEllipse(a, 20, 20, 50, 50); e.Graphics.FillEllipse(a.Brush, x,y,30,30); e.Graphics.DrawLine(a, x+15, y+15, vx, vy); this.BackColor = c; } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.W || e.KeyCode == Keys.Up) { y -= 5; vx = x + 15; vy = y - 15; this.Refresh(); } else if (e.KeyCode == Keys.S || e.KeyCode == Keys.Down) { y += 5; vx = x + 15; vy = y + 45; this.Refresh(); } else if (e.KeyCode == Keys.A || e.KeyCode == Keys.Left) { x -= 5; vx = x - 15; vy = y + 15; this.Refresh(); } else if (e.KeyCode == Keys.D || e.KeyCode == Keys.Right) { x += 5; vx = x + 45; vy = y + 15; this.Refresh(); } } }}