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

📄 bluecommand.cs

📁 经典著作。关于设计模式。全名Introduction to Design Patterns in C# Code.zip。探讨C#中的模式问题。
💻 CS
字号:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections ;

namespace UndoCommand
{
	/// <summary>
	/// draws bluelines and caches list for undo
	/// </summary>
	public class BlueCommand :Command 	{
		protected Color color;
		private PictureBox pbox;
		private ArrayList drawList;
		protected int x, y, dx, dy;
	//-----
		public BlueCommand(PictureBox pbx) {
			pbox = pbx;
			color = Color.Blue ;
			drawList = new ArrayList ();
			x = pbox.Width ;
			dx = -20;
			y = 0;
			dy = 0;
		}
		//-----
		public void Execute() {
		      DrawData dl = new DrawData(x, y, dx, dy);
			drawList.Add(dl);
			x = x + dx;
			y = y + dy;
			pbox.Refresh();
		}
		//-----
		public bool isUndo() {
			return false;
		}
		//-----
		public void Undo() {
			DrawData dl;
			int index = drawList.Count - 1;
			if (index >= 0) {
				dl = (DrawData)drawList[index];
				drawList.RemoveAt(index);
				x = dl.getX();
				y = dl.getY();
			}
			pbox.Refresh();
		}
		//-----
		public void draw(Graphics g) {
			Pen rpen = new Pen(color, 1);
			int h = pbox.Height;
			int w = pbox.Width;

			for (int i = 0; i < drawList.Count ; i++) {
				DrawData dl = (DrawData)drawList[i];
				g.DrawLine(rpen, dl.getX(), dl.getY(), dl.getX() + dx, dl.getDy() + h);
			}
		}
	}
}

⌨️ 快捷键说明

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