本帖最后由 沐华丶 于 2023-2-22 10:20 编辑
我尝试在我原有代码的基础上,在selectionChanging事件中,去重新获取选择区域,但结果似乎并非那么理想。
for (int columnIndex = 0; columnIndex < rowCount; columnIndex++)
{
sv.AddRows(row, 1);
for (int colum = 0; colum <= 15; colum += 4, cardIndex++)
{
if (cardIndex < infos.Count)
{
sv.Cells[row, colum].CellType = textCellType;
sv.Cells[row, colum].Value = "预约时间";
//sv.Cells[row, colum].BackColor = Color.AliceBlue;
sv.Cells[row, colum].Border = GetBorder(1, 0, 0, 1);
sv.Cells[row, colum + 1].CellType = textCellType;
sv.Cells[row, colum + 1].Value = infos[cardIndex].StartDate;
//sv.Cells[row, colum + 1].BackColor = Color.AliceBlue;
sv.Cells[row, colum + 1].Border = GetBorder(0, 0, 0, 1);
sv.Cells[row, colum + 2].CellType = textCellType;
sv.Cells[row, colum + 2].Value = infos[cardIndex].EndDate;
//sv.Cells[row, colum + 2].BackColor = Color.AliceBlue;
sv.Cells[row, colum + 2].Border = GetBorder(0, 0, 1, 1);
sv.Columns[colum + 3].Width = 5;
}
}
cardIndex = cardIndex - 4;
sv.AddRows(row, 1);
for (int colunmIndex = 0; colunmIndex <= 15; colunmIndex += 4, cardIndex++)
{
if (cardIndex < infos.Count)
{
sv.Cells[row, colunmIndex].CellType = textCellType;
//sv.Cells[row, colunmIndex].BackColor = Color.AliceBlue;
sv.Cells[row, colunmIndex].Value = "可预约人数:" + infos[cardIndex].PreLmt ;
sv.Cells[row, colunmIndex].Border = GetBorder(1, 1, 0, 0);
sv.Cells[row, colunmIndex + 1].CellType = textCellType;
sv.Cells[row, colunmIndex + 1].Value = " 已预约人数:";
//sv.Cells[row, colunmIndex + 1].BackColor = Color.AliceBlue;
sv.Cells[row, colunmIndex + 1].Border = GetBorder(0, 1, 0, 0);
sv.Cells[row, colunmIndex + 2].CellType = textCellType;
sv.Cells[row, colunmIndex + 2].Value = infos[cardIndex].PreAppointed ;
sv.Cells[row, colunmIndex + 2].ForeColor = Color.Red;
//sv.Cells[row, colunmIndex + 2].BackColor = Color.AliceBlue;
sv.Cells[row, colunmIndex + 2].Border = GetBorder(0, 1, 1, 0);
sv.Columns[colunmIndex + 3].Width = 5;
}
}
sv.AddRows(row, 1);
sv.Rows[row].Height = 5;
}
}
/// <summary>
/// 画边框
/// </summary>
/// <param name="left"></param>
/// <param name="top"></param>
/// <param name="right"></param>
/// <param name="bottom"></param>
/// <returns></returns>
private ComplexBorder GetBorder(int left, int top, int right, int bottom)
{
ComplexBorder complexBorder = new ComplexBorder(
left > 0 ? new ComplexBorderSide(Color.FromArgb(184, 200, 200), left, System.Drawing.Drawing2D.DashStyle.Solid) : new ComplexBorderSide(Color.Black, left)
, top > 0 ? new ComplexBorderSide(Color.FromArgb(184, 200, 200), top, System.Drawing.Drawing2D.DashStyle.Solid) : new ComplexBorderSide(Color.Black, top)
, right > 0 ? new ComplexBorderSide(Color.FromArgb(184, 200, 200), right, System.Drawing.Drawing2D.DashStyle.Solid) : new ComplexBorderSide(Color.Black, right)
, bottom > 0 ? new ComplexBorderSide(Color.FromArgb(184, 200, 200), bottom, System.Drawing.Drawing2D.DashStyle.Solid) : new ComplexBorderSide(Color.Black, bottom));
return complexBorder;
}
private void FpAppointSelectionChanging(object sender, SelectionChangingEventArgs e)
{
fpAppoint.ActiveSheet.AddSelection(2, 3, 2, 3);
} |