jit推单功能除统计外完成
This commit is contained in:
1 parent
b05de6797e
commit
bbbc12148b
25 files changed
+3130
-1142
No files matched your search
@@ -534,6 +534,205 @@ namespace TemuKJD.Extension
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static void AddVerticalMergeCell(this DataGridView dgv, ConcurrentList<DataGridViewCell> cellLst, bool drawRightBorder = true, Color? VerGridColor = null, Color? VerGridSelectColor = null)
|
||||
{
|
||||
int nHeight = 0;
|
||||
int nLeft = 0;
|
||||
int nTop = 0;
|
||||
int nWidth = 0;
|
||||
|
||||
dgv.RowHeightChanged += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (var cell in cellLst)
|
||||
{
|
||||
if (cell.RowIndex == e.Row.Index)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
//合并列中某一列的列宽变化时,强制重绘
|
||||
dgv.ColumnWidthChanged += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (var cell in cellLst)
|
||||
{
|
||||
if (cell.ColumnIndex == e.Column.Index)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
dgv.SelectionChanged += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (var cell in cellLst)
|
||||
{
|
||||
if (cell.Displayed)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
dgv.Scroll += (s, e) =>
|
||||
{
|
||||
bool has = false;
|
||||
foreach (DataGridViewCell cell in cellLst)
|
||||
{
|
||||
if (cell.Displayed)
|
||||
{
|
||||
dgv.InvalidateCell(cell);
|
||||
has = true;
|
||||
}
|
||||
}
|
||||
if (has)
|
||||
dgv.Update();
|
||||
};
|
||||
//处理重绘事件
|
||||
dgv.CellPainting += (s, e) =>
|
||||
{
|
||||
if (e.RowIndex >= 0 && e.ColumnIndex >= 0) // 重绘单元格
|
||||
{
|
||||
foreach(DataGridViewCell cell in cellLst)
|
||||
{
|
||||
if (cell.RowIndex == e.RowIndex && cell.ColumnIndex == e.ColumnIndex)
|
||||
{
|
||||
nTop = e.CellBounds.Top;
|
||||
nLeft = e.CellBounds.Left;
|
||||
nWidth = e.CellBounds.Width;
|
||||
nHeight = 0;
|
||||
foreach (DataGridViewCell c in cellLst)
|
||||
{
|
||||
nHeight += dgv.Rows[c.RowIndex].Height;
|
||||
}
|
||||
for (int i = 0; i < cellLst.IndexOf(cell); i++)
|
||||
{
|
||||
nTop -= dgv.Rows[cellLst[i].RowIndex].Height;
|
||||
}
|
||||
var rect = new Rectangle(nLeft, nTop, nWidth - 1, nHeight - 1);
|
||||
if (!drawRightBorder)
|
||||
rect = new Rectangle(nLeft, nTop, nWidth, nHeight - 1);
|
||||
|
||||
e.PaintBackground(e.CellBounds, true); // false不绘制单元格背景
|
||||
//e.PaintContent(e.CellBounds); // 绘制单元格内容,此处根据需要决定是否绘制内容
|
||||
|
||||
Brush brush;
|
||||
Pen pen;
|
||||
//if (cellLst.IndexOf(cell) < cellLst.Count - 1)
|
||||
{
|
||||
var color = VerGridColor;
|
||||
// 分隔线
|
||||
if (color == null)
|
||||
{
|
||||
//VerGridColor = Color.FromArgb(229, 229, 229);
|
||||
color = e.RowIndex % 2 == 0 ? dgv.DefaultCellStyle.BackColor : dgv.AlternatingRowsDefaultCellStyle.BackColor;
|
||||
color = e.CellStyle.BackColor;
|
||||
}
|
||||
var selectColor = VerGridSelectColor;
|
||||
if (selectColor == null)
|
||||
//VerGridColorSelect = Color.FromArgb(129, 129, 129);
|
||||
selectColor = dgv.DefaultCellStyle.SelectionBackColor;
|
||||
//if ((dgv.Rows[e.RowIndex].Cells[e.ColumnIndex]).Selected)
|
||||
if (cellLst.Any(c =>c.Selected))
|
||||
{
|
||||
//using (pen = new Pen(selectColor.Value))
|
||||
//{
|
||||
// var rtBounds = e.CellBounds;
|
||||
// //e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top, rtBounds.Right - 1, rtBounds.Bottom - 2); // 右竖线
|
||||
// e.Graphics.DrawLine(pen, rtBounds.Left, rtBounds.Bottom - 1, rtBounds.Right - 2, rtBounds.Bottom - 1); // 下横线
|
||||
//}
|
||||
using (brush = new SolidBrush(selectColor.Value))
|
||||
{
|
||||
e.Graphics.FillRectangle(brush, rect);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//using (pen = new Pen(color.Value))
|
||||
//{
|
||||
// var rtBounds = e.CellBounds;
|
||||
// //e.Graphics.DrawLine(pen, rtBounds.Right - 1, rtBounds.Top, rtBounds.Right - 1, rtBounds.Bottom - 2); // 右竖线
|
||||
// e.Graphics.DrawLine(pen, rtBounds.Left, rtBounds.Bottom - 1, rtBounds.Right - 2, rtBounds.Bottom - 1); // 下横线
|
||||
//}
|
||||
using (brush = new SolidBrush(color.Value))
|
||||
{
|
||||
e.Graphics.FillRectangle(brush, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (cellLst.IndexOf(cell) == cellLst.Count - 1)
|
||||
if (cell is DataGridViewImageCell == false)
|
||||
{
|
||||
var color = e.CellStyle.ForeColor;
|
||||
if (cellLst.Any(c => c.Selected))
|
||||
{
|
||||
color = e.CellStyle.SelectionForeColor;
|
||||
}
|
||||
using (brush = new SolidBrush(color))
|
||||
{
|
||||
//StringFormat stringFormat = new StringFormat();
|
||||
//stringFormat.Alignment = StringAlignment.Near;
|
||||
//stringFormat.LineAlignment = StringAlignment.Near;
|
||||
//stringFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces; // 确保尾部空格被计算在内
|
||||
//stringFormat.Trimming = StringTrimming.Character; // 处理超出宽度的字符
|
||||
//stringFormat.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, cell.Value.ParseToString().Length) }); // 设置测量范围
|
||||
|
||||
SizeF textSize = TextRenderer.MeasureText(cell.Value.ParseToString(), e.CellStyle.Font, new Size(nWidth - 10, nHeight), TextFormatFlags.WordBreak);
|
||||
//单元列移出可见范围后将不再移动,需要强制改变绘制文字的位置
|
||||
if (nLeft < 0)
|
||||
nLeft = e.CellBounds.Right - nWidth;
|
||||
PointF point = new PointF(nLeft + 1, nTop + (nHeight - textSize.Height) / 2);
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Center"))
|
||||
point.X = nLeft + (nWidth - textSize.Width) / 2;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Right"))
|
||||
point.X = nLeft + nWidth - textSize.Width - 1;
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Top"))
|
||||
point.Y = nTop + 4;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Bottom"))
|
||||
point.Y = nTop + nHeight - textSize.Height - 4;
|
||||
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
RectangleF rectF = new RectangleF(point.X, point.Y, nWidth - 10, nHeight - 10);
|
||||
//e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, point);
|
||||
e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, rectF);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var img = cell.Value as Image;
|
||||
|
||||
PointF point = new PointF(nLeft, nTop + (nHeight - img.Height) / 2);
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Center"))
|
||||
point.X = nLeft + (nWidth - img.Width) / 2;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Right"))
|
||||
point.X = nLeft + nWidth - img.Width - 1;
|
||||
if (e.CellStyle.Alignment.ToString().Contains("Top"))
|
||||
point.Y = nTop + 4;
|
||||
else if (e.CellStyle.Alignment.ToString().Contains("Bottom"))
|
||||
point.Y = nTop + nHeight - img.Height;
|
||||
e.Graphics.DrawImage(img, point);
|
||||
//RectangleF rectF = new RectangleF(point.X, point.Y, nWidth - 10, nHeight - 10);
|
||||
//e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, point);
|
||||
//e.Graphics.DrawString(cell.Value.ParseToString(), e.CellStyle.Font, brush, rectF);
|
||||
}
|
||||
e.Handled = true; // 告知系统不再处理单元格绘制事件
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static void AddImgColumn(this DataGridView dgv, string imgColumn, string imgPathColumn, bool isSetHttpsHttp = true)
|
||||
{
|
||||
dgv.Scroll += (s, e) =>
|
||||
|
||||
Reference in new issue
Block a user