#region
|
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Windows.Forms;
|
|
#endregion
|
|
namespace CSFrameworkV5.UserCustom
|
{
|
public class GZTableClass
|
{
|
public static GZTable GetGZTable(Control col, int width, int height)
|
{
|
var PanWidth = col.Width - 20; //预留给滚动条20像素
|
var PanHeight = col.Height - 20; //预留给滚动条20像素
|
//计算表格的行数和列数
|
var ColumnCoount = PanWidth / width;
|
var RowCount = PanHeight / height;
|
return new GZTable(ColumnCoount, width, height);
|
}
|
|
public static GZTable GetGZTable(int width, int height, int CellCount)
|
{
|
return new GZTable(CellCount, width, height);
|
}
|
}
|
|
public class GZCell
|
{
|
private int _ColIndex;
|
|
private Control _ContainControl;
|
|
private int _Height;
|
|
//private Point _Location;
|
private bool _IsUsed;
|
private int _RowIndex;
|
|
private int _Width;
|
///// <summary>
|
///// 构造函数,指定单元格坐标
|
///// </summary>
|
///// <param name="Width">单元格宽度</param>
|
///// <param name="Height">单元格高度</param>
|
//public GZCell(int Width, int Height, Point Location)
|
//{
|
// _Width = Width;
|
// _Height = Height;
|
// _Location = Location;
|
//}
|
|
/// <summary>
|
/// 构造函数,指定第几行第几列
|
/// </summary>
|
/// <param name="Width">单元格宽度</param>
|
/// <param name="Height">单元格高度</param>
|
public GZCell(int Width, int Height, int RowIndex, int ColIndex)
|
{
|
_Width = Width;
|
_Height = Height;
|
_RowIndex = RowIndex;
|
_ColIndex = ColIndex;
|
}
|
|
public int ColIndex => _ColIndex;
|
|
public Control ContainControl
|
{
|
get => _ContainControl;
|
set
|
{
|
_ContainControl = value;
|
UpdateControl();
|
}
|
}
|
|
/// <summary>
|
/// 单元格高度
|
/// </summary>
|
public int Height => _Height;
|
|
public bool IsUsed
|
{
|
get => _IsUsed;
|
set => _IsUsed = value;
|
}
|
|
public Point Location
|
{
|
get
|
{
|
var W = Width * ColIndex + 20;
|
var H = Height * RowIndex;
|
|
return new Point(W, H);
|
}
|
}
|
|
public int RowIndex => _RowIndex;
|
|
/// <summary>
|
/// 单元格宽度
|
/// </summary>
|
public int Width => _Width;
|
|
public void UpdateControl()
|
{
|
if (_ContainControl != null)
|
{
|
_ContainControl.Location = Location;
|
IsUsed = true;
|
}
|
else
|
{
|
IsUsed = false;
|
}
|
}
|
}
|
|
public class GZRow
|
{
|
private List<GZCell> lstGZRow = new List<GZCell>();
|
|
public GZRow(int ColCount, int width, int height, int RowIndex)
|
{
|
for (var i = 0; i < ColCount; i++)
|
lstGZRow.Add(new GZCell(width, height, RowIndex, i));
|
}
|
|
public GZCell this[int Index] => lstGZRow[Index];
|
///// <summary>
|
///// 删除单元格
|
///// </summary>
|
///// <param name="GCell"></param>
|
//public void RemoveCell(GZCell GCell)
|
//{
|
// lstGZRow.Remove(GCell);
|
//}
|
///// <summary>
|
///// 删除单元格
|
///// </summary>
|
///// <param name="Index"></param>
|
//public void RemoveCell(int Index)
|
//{
|
// RemoveCell(lstGZRow[Index]);
|
//}
|
|
public int Count()
|
{
|
return lstGZRow.Count;
|
}
|
}
|
|
public class GZTable
|
{
|
private int _CellCount;
|
private int _CellHeight;
|
private int _CellWidth;
|
private List<GZRow> lstRow = new List<GZRow>();
|
|
public GZTable(int ColumnCount, int CellWidth, int CellHeight)
|
{
|
_CellCount = ColumnCount;
|
_CellWidth = CellWidth;
|
_CellHeight = CellHeight;
|
}
|
|
public int CellCount => _CellCount;
|
|
public int CellHeight => _CellHeight;
|
|
public int CellWidth => _CellWidth;
|
|
public GZRow this[int Index]
|
{
|
get
|
{
|
if (Index <= lstRow.Count - 1) return lstRow[Index];
|
|
return null;
|
}
|
}
|
|
public int RowCount => lstRow.Count;
|
|
/// <summary>
|
/// 添加一行
|
/// </summary>
|
/// <param name="CellNum"></param>
|
/// <param name="width"></param>
|
/// <param name="height"></param>
|
public void AddRow()
|
{
|
var GRow = new GZRow(_CellCount, CellWidth, CellHeight, RowCount);
|
lstRow.Add(GRow);
|
}
|
|
public GZCell GetCellByPoint(Point P)
|
{
|
var X = P.X;
|
var Y = P.Y;
|
|
if (X < 0 || Y < 0) return null;
|
|
var PanWidth = CellCount * CellWidth;
|
var PanHeight = RowCount * CellHeight;
|
if (X < PanWidth && Y < PanHeight)
|
{
|
var I = X / CellWidth - 1;
|
var J = Y / CellHeight - 1;
|
if (X % CellWidth > 5) I++;
|
|
if (Y % CellHeight > 5) J++;
|
|
if (I < 0 || J < 0) return null;
|
|
return lstRow[J][I];
|
}
|
|
return null;
|
}
|
|
///// <summary>
|
///// 删除行
|
///// </summary>
|
///// <param name="Grow"></param>
|
//public void RemoveRow(GZRow Grow)
|
//{
|
// lstRow.Remove(Grow);
|
//}
|
///// <summary>
|
///// 删除行
|
///// </summary>
|
///// <param name="index"></param>
|
//public void RemoveRow(int index)
|
//{
|
// RemoveRow(lstRow[index]);
|
//}
|
}
|
}
|