#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;
/////
///// 构造函数,指定单元格坐标
/////
///// 单元格宽度
///// 单元格高度
//public GZCell(int Width, int Height, Point Location)
//{
// _Width = Width;
// _Height = Height;
// _Location = Location;
//}
///
/// 构造函数,指定第几行第几列
///
/// 单元格宽度
/// 单元格高度
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();
}
}
///
/// 单元格高度
///
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;
///
/// 单元格宽度
///
public int Width => _Width;
public void UpdateControl()
{
if (_ContainControl != null)
{
_ContainControl.Location = Location;
IsUsed = true;
}
else
{
IsUsed = false;
}
}
}
public class GZRow
{
private List lstGZRow = new List();
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];
/////
///// 删除单元格
/////
/////
//public void RemoveCell(GZCell GCell)
//{
// lstGZRow.Remove(GCell);
//}
/////
///// 删除单元格
/////
/////
//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 lstRow = new List();
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;
///
/// 添加一行
///
///
///
///
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;
}
/////
///// 删除行
/////
/////
//public void RemoveRow(GZRow Grow)
//{
// lstRow.Remove(Grow);
//}
/////
///// 删除行
/////
/////
//public void RemoveRow(int index)
//{
// RemoveRow(lstRow[index]);
//}
}
}