folder.cs

来自「Csharp设计模式图书加源代码是csharp程序员学习模式编程的一本好书」· CS 代码 · 共 41 行

CS
41
字号
using System;
using System.Drawing ;
namespace Flyweight
{
	/// <summary>
	/// Summary description for Folder.
	/// </summary>
	public class Folder 	{
		//Draws a folder at the specified coordinates
		private const int w  = 50;
		private const int h = 30;
		private Pen blackPen, whitePen;
	    private Pen grayPen;																		
		private SolidBrush backBrush, blackBrush;
		private Font fnt;
		//------
		public Folder(Color col) 		{
			backBrush = new SolidBrush(col);
			blackBrush = new SolidBrush(Color.Black);
			blackPen = new Pen(Color.Black);
			whitePen = new Pen(Color.White);
			grayPen = new Pen(Color.Gray);
			fnt = new Font("Arial", 12);
		}
		//-----
		public void draw(Graphics g, int x, int y, string title) {
			g.FillRectangle(backBrush, x, y, w, h);
			g.DrawRectangle(blackPen, x, y, w, h);
			g.DrawLine(whitePen, x + 1, y + 1, x + w - 1, y + 1);
			g.DrawLine(whitePen, x + 1, y, x + 1, y + h);
	
		    g.DrawRectangle(blackPen, x + 5, y - 5, 15, 5);
			g.FillRectangle(backBrush, x + 6, y - 4, 13, 6);

			g.DrawLine(grayPen, x, y + h - 1, x + w, y + h - 1);
			g.DrawLine(grayPen, x + w - 1, y, x + w - 1, y + h - 1);
			g.DrawString(title, fnt, blackBrush, x, y + h + 5);
		}
	}
}

⌨️ 快捷键说明

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