colorchain.cs
来自「c#设计模式随书源码 c#设计模式随书源码」· CS 代码 · 共 39 行
CS
39 行
using System;
using System.Collections ;
using System.Drawing ;
using System.Windows.Forms ;
namespace Chain
{
/// <summary>
/// receives color names in chain
/// </summary>
public class ColorChain : Chain {
private Hashtable colHash; //color list kept here
private Panel panel; //color goes here
//-----
public ColorChain(Panel pnl) {
panel = pnl; //save reference
//create Hash table to correlate color names
//with actual Color objects
colHash = new Hashtable ();
colHash.Add ("red", Color.Red);
colHash.Add ("green", Color.Green);
colHash.Add ("blue", Color.Blue);
}
//-----
public override void sendToChain(string mesg) {
mesg = mesg.ToLower ();
try {
Color c = (Color)colHash[mesg];
//if this is a color, put it in the panel
panel.BackColor =c;
}
catch (NullReferenceException e) {
//send on if this doesn't work
sendChain(mesg);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?