📄 card.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace LotsOfFun.Games
{
public enum Suit
{
Clubs, Hearts, Diamonds, Spades
};
public enum FaceValue
{
Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King
};
public partial class Card : UserControl
{
SortedList m_images = new SortedList();
public Card()
{
InitializeComponent();
m_images.Add(Suit.Clubs, new Icon("C:\\icon\\clubs.ico"));
m_images.Add(Suit.Diamonds, new Icon("C:\\icon\\diamonds.ico"));
m_images.Add(Suit.Hearts, new Icon("C:\\icon\\hearts.ico"));
m_images.Add(Suit.Spades, new Icon("C:\\icon\\spades.ico"));
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// Card
//
this.Name = "Card";
this.Size = new System.Drawing.Size(60, 78);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Card_Paint);
this.SizeChanged += new System.EventHandler(this.Card_SizeChanged);
this.ResumeLayout(false);
}
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)(this.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 + -