/*
* user: administrator
* date: 2007-7-2 time: 15:49
*/
//一些指令,作用是畫圓,畫方,畫線,三個主要的指令,
//指令模式最主的特點是,可以友善的加入權限的判斷
//最後便使用了一個代理模式,來實作這個權限的判斷
//
using system;
using system.drawing;
using system.windows.forms;
namespace securitycommand{
public abstract class command{
private graphics g;
public command(){}
public graphics cav{
get{return g;}
set{g=value;}
}
public abstract void execute();
}
public class circlecommand:command{
public circlecommand(){}
public override void execute()
{
pen p=new pen(color.red);
this.cav.drawellipse(p,0,0,100,100);
public class linecommand:command{
public linecommand(){}
this.cav.drawline(p,0,0,100,100);
public class rectcommand:command{
public rectcommand(){}
this.cav.drawrectangle(p,0,0,100,100);
public class securitycommand:command{
private command c;
public securitycommand(command c){
this.c=c;
messagebox.show("權限判斷"+c.gettype().name);
c.execute();
}
//界面的函數
* date: 2007-7-2 time: 15:51
using securitycommand;
namespace mymemonto
{
/// <summary>
/// description of mydraw.
/// </summary>
public partial class mydraw : form
{
private command circle;
private command line;
private command rect;
private command scircle;
private command sline;
private command srect;
[stathread]
public static void main(){
application.run(new mydraw());
public mydraw()
//
// the initializecomponent() call is required for windows forms designer support.
initializecomponent();
init();
scircle=new securitycommand.securitycommand(circle);
sline=new securitycommand.securitycommand(line);
srect=new securitycommand.securitycommand(rect);
// todo: add constructor code after the initializecomponent() call.
void init(){
circle=new securitycommand.circlecommand();
circle.cav=this.creategraphics();
line=new securitycommand.linecommand();
line.cav=this.creategraphics();
rect=new securitycommand.rectcommand();
rect.cav=this.creategraphics();
void tsmcircleclick(object sender, eventargs e)
scircle.execute();
void tsmlineclick(object sender, eventargs e)
sline.execute();
void tsmrectclick(object sender, eventargs e)
srect.execute();
void tsmexitclick(object sender, eventargs e)
application.exit();