利用C#画出如下的表格
代码附上
private void UpdateTable()
{
/* 生成表格文件 */
int x1 = 55; /* 表框起始横坐标 */
int y1 = 100; /* 表框起始纵坐标 */
int x2 = x1 + 2; /* 文字起始横坐标 */
int y2 = y1 + 5; /* 文字起始纵坐标 */
int z = 30; /* 行宽 */
int rowHead = 0; /* 每行数据的高度初始位置 */
int columnHead = 200; /* 第一列宽度 */
int zWidth = 141; /* 测量数据列宽 */
int zWidthTwice = zWidth * 2; /* 两倍测量数据列宽 */
int sum = 5; /* 目标位置点个数 */
int row = 3; /* 测量次数 */
int tempDelta = 50; /* 调整文字居中变量 */
int width = 320 + sum * zWidthTwice; /* 图片宽度 */
int height = 940 + 2 * z * row; /* 图片高度 */
int tableWidth = columnHead + sum * zWidthTwice; /* 表格宽度 */
Bitmap bmp = new Bitmap(width, height); /* 新建一个图片对象 */
Graphics g = Graphics.FromImage(bmp); /* 利用该图片对象生成画板 */
Font font = new Font("宋体", 15); /* 设置字体颜色 */
SolidBrush brush = new SolidBrush(Color.Black); /* 新建一个画刷,到这里为止,我们已经准备好了画板、画刷和数据 */
Pen p = new Pen(Color.Black, 1); /* 定义了一个黑色,宽度为1的画笔 */
g.Clear(Color.FromArgb(255, 255, 255)); /* 设置白色背景 */
/* 第1行数据 */
rowHead = 0;
g.DrawRectangle(p, x1, y1 + rowHead, tableWidth, z); /* 在画板上画矩形,起始坐标为(x1,y1),宽为800,高为30 */
string tempTitle = "GB/T 17421.2-2000 统计数表————线性测校————线性位移(x)";
g.DrawString(tempTitle, font, brush, x2, y2);
/* 绘制文字,起始坐标为(x2, y2) */
/* 第2行数据 */
rowHead = z;
g.DrawRectangle(p, x1, y1 + rowHead, columnHead + zWidthTwice, z);
g.DrawRectangle(p, x1 + columnHead + zWidthTwice, y1 + rowHead, zWidthTwice, z);
g.DrawRectangle(p, x1 + columnHead + 2 * zWidthTwice, y1 + rowHead, zWidthTwice, z);
g.DrawRectangle(p, x1 + tableWidth - (sum - 3) * zWidthTwice, y1 + rowHead, (sum - 3) * zWidthTwice, z);
g.DrawString("机器编号:" + GlobalData.objMachineName, font, brush, x2, y2 + rowHead);
g.DrawString("轴:" + GlobalData.objAxis, font, brush, x2 + columnHead + zWidthTwice, y2 + rowHead);
g.DrawString("日期:" + GlobalData.objTime, font, brush, x2 + columnHead + 2 * zWidthTwice, y2 + rowHead);
g.DrawString("操作者:" + GlobalData.objWorker, font, brush, x2 + tableWidth - (sum - 3) * zWidthTwice, y2 + rowHead);
/* 第3行数据 */
rowHead += z;
g.DrawRectangle(p, x1, y1 + rowHead, tableWidth, z);
tempTitle = "计算值和误差值(单位: ";
switch (n)
{
case 1:
if (GlobalData.meaUnit.Equals("公制"))
{
tempTitle = tempTitle + "mm)";
}
else
{
tempTitle = tempTitle + "inch)";
}
break;
case 2:
case 3:
tempTitle = tempTitle + "mrad)";
break;
default:
break;
}
g.DrawString(tempTitle, font, brush, x2, y2 + rowHead);
/* 第4行数据 */
rowHead += z;
g.DrawRectangle(p, x1, y1 + rowHead, columnHead, z);
g.DrawString("目标点数i", font, brush, x2, y2 + rowHead);
for (int i = 0; i < sum; i++)
{
g.DrawRectangle(p, x1 + 200 + i * zWidthTwice, y1 + 3 * z, zWidthTwice, z);
g.DrawString((i + 1).ToString(), font, brush, x2 + columnHead+ i * zWidthTwice, y2 + 3 * z);
}
/* 第5行数据 */
rowHead += z;
g