📄 rectanglearray.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -