|
|
|
ช่วยผมด้วยครับถามเรื่องใช้ function Rectangle>Event Cell painting>datagridview:: โปรแกรม vs2019 ครับ หัดเขียนครับ มี 2 คำถามครับ |
|
|
|
|
|
|
|
อันนี้ Code ครับ
private void gidDetail_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
int heightOffset = -5;
int widthOffset = -1;
int xOffset = -1;
int yOffset = 4;
string[] hmerge = { "ขอบ5+V2X(บน)+V2(ล่าง)","ขอบ5+V3A(บน)+V3A(ล่าง)","ขอบ7+V2X(บน)+V2X(ล่าง)","ขอบ7+V2X(บน)+V3A(ล่าง)","ขอบ7+V3A(บน)+V3A(ล่าง)","ขอบPocket+V3A(บน)+V3A(ล่าง)",
"มุม7+V3A(บน)+V3A(ล่าง)","ยิงบ๊อก(ขอบ5)+V3A(บน)","ยิงบ๊อก(ขอบ7)+V3A(บน)","หุ้มโกลด์สปริง", "รวม"
};
//int columnIndex = 7;
//Rectangle headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnIndex, 0, true);
//int xCord = headerCellRectangle.Location.X + xOffset;
//int yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
//int mergedHeaderWidth = gidDetail.Columns[columnIndex].Width + gidDetail.Columns[columnIndex + 5].Width + widthOffset;
//Rectangle mergedHeaderRect = new Rectangle(xCord, yCord, mergedHeaderWidth, headerCellRectangle.Height + heightOffset);
//e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);
for (int xcol = 0; xcol < hmerge.Count(); xcol++)
{
int columnx = 0;
switch (xcol)
{
case 0:
columnx = 7;
Rectangle headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
int mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
int xCord = headerCellRectangle.Location.X + xOffset;
int yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
float xcordfont = e.Graphics.MeasureString(hmerge[0].Remove(hmerge[0].Length - 1), Font).Width;
int xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;
Rectangle mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);
e.Graphics.DrawString(hmerge[0], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
case 1:
columnx = 12;
headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
xCord = headerCellRectangle.Location.X + xOffset;
yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
xcordfont = e.Graphics.MeasureString(hmerge[1].Remove(hmerge[1].Length - 1), Font).Width;
xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;
mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);
e.Graphics.DrawString(hmerge[1], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
case 2:
columnx = 17;
headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
xCord = headerCellRectangle.Location.X + xOffset;
yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
xcordfont = e.Graphics.MeasureString(hmerge[2].Remove(hmerge[2].Length - 1), Font).Width;
xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;
mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);
e.Graphics.DrawString(hmerge[2], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
case 3:
columnx = 22;
headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
xCord = headerCellRectangle.Location.X + xOffset;
yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
xcordfont = e.Graphics.MeasureString(hmerge[3].Remove(hmerge[3].Length - 1), Font).Width;
xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;
mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);
e.Graphics.DrawString(hmerge[3], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
}
}
}
|
|
|
|
|
Date :
2020-11-02 11:50:49 |
By :
tuipoktui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
วิธีที่ดีที่สุด (ยืดหยุ่นและง่าย) คือ HTML + WebView2
|
|
|
|
|
Date :
2020-11-23 10:44:40 |
By :
PhrayaDev |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|