第一个图片是我想要的效果,绘制出来的表格出现在窗体的下面,上面留有一部分空白地可以放其他控件,第二张图是我弄的,不知道怎么样才能变成第一张的效果,求大神赐教
//下面是代码
private const int Unit_length = 32;//单位格大小
private int DrawStep = 8;//默认绘制单位.放大作用
private const int Y_Max = 512;//Y轴最大数值
private const int MaxStep = 33;//绘制单位最大值
private const int MinStep = 1;//绘制单位最小值
private const int StartPrint = 32;//点坐标偏移量
private List<byte> DataList = new List<byte>();//数据结构----线性链表
private Pen TablePen = new Pen(Color.FromArgb(0x00, 0x00, 0x00));//轴线颜色
private Pen LinesPen = new Pen(Color.FromArgb(0xa0, 0x00, 0x00));//波形颜色
private void Form1_Paint(object sender, PaintEventArgs e)
{
String Str = "";
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
e.Graphics.FillRectangle(Brushes.White, e.Graphics.ClipBounds);
//Draw 纵向轴绘制
for (int i = 0; i <= this.ClientRectangle.Width / Unit_length; i++)
{
e.Graphics.DrawLine(TablePen, StartPrint + i * Unit_length, StartPrint, StartPrint + i * Unit_length, StartPrint + Y_Max);//画线
gp.AddString((i * (Unit_length / DrawStep)).ToString(), this.Font.FontFamily, (int)FontStyle.Regular,
15, new RectangleF(StartPrint + i * Unit_length - 7,
this.ClientRectangle.Height - StartPrint + 4, 400, 50), null);//添加文字
}
//Draw 横向轴绘制
for (int i = 0; i <= this.ClientRectangle.Height / Unit_length; i++)
{
e.Graphics.DrawLine(TablePen, StartPrint, (i + 1) * Unit_length, this.ClientRectangle.Width, (i + 1) * Unit_length);//画线
Str = ((16 - i) * 16).ToString("X");
Str = "0x" + (Str.Length == 1 ? Str + "0" : Str);
if (i == 0)
Str = "0xFF";
if (i == 17)
break;
gp.AddString(Str, this.Font.FontFamily, (int)FontStyle.Regular, 15, new RectangleF(0, StartPrint + i * Unit_length - 8, 400, 25), null);//添加文字
}
e.Graphics.DrawPath(Pens.Black, gp);//写文字
for (int i = 0; i < DataList.Count - 1; i++)//绘制波形
{
e.Graphics.DrawLine(LinesPen, StartPrint + i * DrawStep, 17 * Unit_length - DataList[i] * 2, StartPrint + (i + 1) * DrawStep, 17 * Unit_length - DataList[i + 1] * 2);
}
}