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

📄 card.cs

📁 OOP With Microsoft VB.NET And Csharp Step By Step
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace BetterCard
{
	public enum Suit 
	{
		Clubs, Spades, Diamonds, Hearts
	};

	public enum FaceValue 
	{
		Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,
		Jack,Queen,King
	};

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

		static SortedList m_images = new SortedList();
		
		public Card()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

		}

		static Card()
		{
			System.Reflection.Assembly assembly;
			assembly = System.Reflection.Assembly.GetExecutingAssembly();
			string assemblyName =assembly.GetName().Name;
			System.IO.Stream iconStream;
			string resourceName;
			Icon theIcon;
			object theSuit;
			string[] suitNames = Enum.GetNames(typeof(Suit));
			for (int aSuit = 0; aSuit < suitNames.Length; aSuit++)
			{
				resourceName = assemblyName + "." + suitNames[aSuit] + ".ico";
				iconStream = assembly.GetManifestResourceStream(resourceName);
				theIcon = new Icon(iconStream);
				theSuit = Enum.Parse(typeof(Suit), suitNames[aSuit], true);
				m_images.Add(theSuit, theIcon);
			}
		}


		/// <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()
		{
			// 
			// Card
			// 
			this.Name = "Card";
			this.Size = new System.Drawing.Size(60, 75);
			this.SizeChanged += new System.EventHandler(this.Card_SizeChanged);
			this.Paint += new System.Windows.Forms.PaintEventHandler(this.Card_Paint);

		}
		#endregion


		public Card(Suit suit,FaceValue faceValue) : this()
		{
			m_suit =suit;
			m_faceValue =faceValue;
		}

		private FaceValue m_faceValue = FaceValue.Ace;
		[Category("Game")]
		[Description("Face value of the card.")]
		public FaceValue FaceValue 
		{
			get {return m_faceValue;}
			set 
			{
				m_faceValue =value;
				this.Refresh();
			}
		}

		private Suit m_suit =Suit.Hearts;
		[Category("Game")]
		[Description("Suit (Hearts,Spades,Diamonds,Clubs)")]
		public Suit Suit 
		{
				get {return m_suit;}
			set 
			{
				m_suit =value;
				this.Refresh();
			}
		}

		private bool m_faceUp =true;

		private void Card_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Graphics g =this.CreateGraphics();
			g.DrawRectangle(System.Drawing.Pens.Black, 0, 0,
				this.ClientRectangle.Width-1, this.ClientRectangle.Height-1);
			if (this.m_faceUp)
			{
				this.BackColor =Color.White;
				g.DrawString(this.m_faceValue.ToString(),
					new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold),
					System.Drawing.Brushes.Black, 3, 3);
				g.DrawIcon((Icon)(m_images[m_suit]), 14, 40);
			}
			else 
			{
				this.BackColor =Color.Blue;
			}
		}
		
		public const int FixedWidth =60;
		public const int FixedHeight =75;

		private void Card_SizeChanged(object sender, System.EventArgs e)
		{
			this.Size =new Size(FixedWidth,FixedHeight);
		}
	
		[Category("Game")]
		[Description("Is the card face up?")]
		public bool FaceUp 
		{
			get {return m_faceUp;}
			set 
			{
				m_faceUp =value;
				this.Refresh();
			}
		}



	}
}

⌨️ 快捷键说明

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