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

📄 facecontrol.cs

📁 软件名称:挖雷 游戏版 本:1.01编程语言:Visual Studio .NET C# (Beta 2)调试环境:WINDOWS 2000 Professional运行环境:需要 Microsoft
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace MineClearance
{
	/// <summary>
	/// Summary description for FaceControl1.
	/// </summary>
	public class FaceControl : System.Windows.Forms.UserControl
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		//状态锁定

		public enum FaceState
		{
			Up,
			Down,
			Startle,
			Die
		};

		//状态设置
		private FaceState State;
		public FaceState faceState
		{
			get
			{
				return State;
			}
			set
			{
				if(State != value)
				{
					State = value;
					ReDraw();
				}
			}
		}

		public FaceControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitForm call
			this.Size = new Size(22, 22);
			faceState = FaceState.Up;
		}

		/// <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 Component 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()
		{
			// 
			// FaceControl
			// 
			this.BackColor = System.Drawing.Color.Gainsboro;
			this.Name = "FaceControl";
			this.Size = new System.Drawing.Size(48, 32);

		}
		#endregion

		protected override void OnPaint(PaintEventArgs e)
		{
			ReDraw();
		}

		protected override void OnMouseDown(MouseEventArgs e)
		{
			faceState = FaceState.Down;
		}

		protected override void OnMouseUp(MouseEventArgs e)
		{
			faceState = FaceState.Up;
		}

		//画立体方框
		private void ColorBox(int x1, int y1, int x2, int y2, int PenWidth, bool Down, bool Fill, Color FillColor)
		{
			System.Drawing.Graphics g = this.CreateGraphics();
			System.Drawing.Pen p = new Pen(Color.White, 1);//确定画笔的颜色和粗细
			for(; PenWidth > 0; PenWidth --)
			{
				p.Color = (Down == false)? Color.White: Color.Gray;
				g.DrawLine( p, x1, y1, x2, y1);
				g.DrawLine( p, x1, y1, x1, y2);
				p.Color = (Down == false)? Color.Gray: Color.White;
				g.DrawLine( p , x2, y2, x2, y1);
				g.DrawLine( p , x2, y2, x1, y2);
				x1 ++; y1 ++;
				x2 --; y2 --;
			}

			if( Fill == true )	g.FillRectangle(new SolidBrush(FillColor), x1, y1, x2 - x1 + 1, y2 - y1 + 1);
		}

		//在指定位置画物件
		public void ReDraw()
		{
			System.Drawing.Graphics g = this.CreateGraphics();
			System.Drawing.Pen p = new Pen(Color.Black, 1);//确定画笔的颜色和粗细
			System.Drawing.Color textColor = new Color();

			int x=0,y=0;
			switch(faceState)
			{
				case FaceState.Up://画未按下笑脸
					x = this.ClientSize.Width / 2 - 10;
					y = 0;
					ColorBox(x, y, x + 20, y + 20, 2, false, true, Color.Gainsboro);
					g.DrawEllipse(p, x+2,y+2,15,15);
					g.FillEllipse(new SolidBrush(Color.Yellow), x + 3, y + 3 , 13, 13);
					g.DrawArc(p, x+4, y+4, 11,10,55,70);
					p.Width = 2;
					g.DrawLine(p, x+6,y+8,x + 8,y + 8);
					g.DrawLine(p, x+12,y+8,x + 14,y + 8);
					break;
				case FaceState.Down://画按下笑脸
					x = this.ClientSize.Width / 2 - 10;
					y = 0;
					ColorBox(x, y, x + 20, y + 20, 2, true, true, Color.Gainsboro);
					g.DrawEllipse(p, x+2,y+2,15,15);
					g.FillEllipse(new SolidBrush(Color.Yellow), x + 3, y + 3 , 13, 13);
					g.DrawArc(p, x+4, y+4, 11,10,55,70);
					p.Width = 2;
					g.DrawLine(p, x+6,y+8,x + 8,y + 8);
					g.DrawLine(p, x+12,y+8,x + 14,y + 8);
					break;
				case FaceState.Startle://画惊险脸
					x = this.ClientSize.Width / 2 - 10;
					y = 0;
					ColorBox(x, y, x + 20, y + 20, 2, false, true, Color.Gainsboro);
					g.DrawEllipse(p, x+2,y+2,15,15);
					g.FillEllipse(new SolidBrush(Color.Yellow), x + 3, y + 3 , 13, 13);
					g.DrawEllipse(p, x+7,y+10,4,4);
					p.Width = 2;
					g.DrawLine(p, x+6,y+8,x + 8,y + 8);
					g.DrawLine(p, x+12,y+8,x + 14,y + 8);
					break;
				case FaceState.Die://画死亡脸
					x = this.ClientSize.Width / 2 - 10;
					y = 0;
					ColorBox(x, y, x + 20, y + 20, 2, false, true, Color.Gainsboro);
					g.DrawEllipse(p, x+2,y+2,15,15);
					g.FillEllipse(new SolidBrush(Color.Yellow), x + 3, y + 3 , 13, 13);
					g.DrawArc(p, x+4, y+11, 11,18,-60,-60);
					p.Width = 2;
					g.DrawLine(p, x+6,y+8,x + 8,y + 8);
					g.DrawLine(p, x+12,y+8,x + 14,y + 8);
					break;
			}
		}

	}
}

⌨️ 快捷键说明

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