rectanglearray.cs

来自「这是网上下载的很好的串口发短信的程序! 是用VC++来做的」· CS 代码 · 共 64 行

CS
64
字号
using System;
using System.Drawing;
using System.Collections.Specialized;

namespace DDGameHelper
{
	/// <summary>
	/// RectangleArray 的摘要说明。
	/// </summary>
	public class RectangleArray
	{
		protected Rectangle[] _rectangles;
		public Rectangle[] Rectangles{get{return _rectangles;}set{_rectangles=value;}}
		public RectangleArray()
		{
			_rectangles = new Rectangle[0];
		}
		public RectangleArray(int totalWidth, int totalHeight, int cellWidth, int cellHeight, int count)
		{
			_rectangles = RectArrayMaker(totalWidth, totalHeight, cellWidth, cellHeight, count);
		}
		/// <summary>
		/// Rect数组 创建器(根据 Rect 及 bitmap 的大小自动创建 count 个 Rect)
		/// </summary>
		public static Rectangle[] RectArrayMaker(int totalWidth, int totalHeight, int cellWidth, int cellHeight, int count)
		{
			int w = totalWidth / cellWidth;
			int h = totalHeight / cellHeight;
			Rectangle[] rc = new Rectangle[0];
			if(count>0)
			{
				rc = new Rectangle[count];

				for (int i = 0; i < h; i++)
				{
					for (int j = 0; j < w; j++)
					{
						int c = i * h + j;
						if (c >= count)return rc;
						System.Drawing.Point p = new System.Drawing.Point(j * cellWidth, i * cellHeight);
						rc[c] = new System.Drawing.Rectangle(p, new Size(cellWidth, cellHeight));
					}
				}
			}
			else
			{
				rc = new Rectangle[w * h];

				for (int i = 0; i < h; i++)
				{
					for (int j = 0; j < w; j++)
					{
						System.Drawing.Point p = new System.Drawing.Point(j * cellWidth, i * cellHeight);
						rc[i * w + j] = new System.Drawing.Rectangle(p, new Size(cellWidth, cellHeight));
					}
				}
			}
			return rc;
		}

	}

}

⌨️ 快捷键说明

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