因為項目需要,使用GDI畫一個全坐標系統圖,並嵌入PDF文件,方便打印。
效果圖如下:
一般的坐標圖僅有右上的四分之一,此圖則是全坐標的,輸入是四個點的坐標,可以是負值。
代碼:
代碼
Bitmap bitmap = new Bitmap(this.Width, this.Height, PixelFormat.Format24bppRgb);
Graphics g=Graphics.FromImage(bitmap);
//Graphics g = this.CreateGraphics();
g.Clear(Color.White);
Font font = new Font(Font.Name, 11);
SolidBrush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(Color.Black);
pen.EndCap = LineCap.ArrowAnchor;
pen.DashStyle = DashStyle.Solid;
//坐標軸
Point pCenter = new Point(300, 260);
g.DrawLine(pen, new Point(pCenter.X - 200, pCenter.Y), new Point(pCenter.X + 200, pCenter.Y));//x
g.DrawLine(pen, new Point(pCenter.X, pCenter.Y + 200), new Point(pCenter.X, pCenter.Y - 200));//y
//軸標格
for (int i = 0; i < 5; i++)
{
g.DrawLine(Pens.Black, new Point(pCenter.X - iX * i, pCenter.Y), new Point(pCenter.X - iX * i, pCenter.Y - 4));//x
g.DrawString((-i).ToString(), font, brush, new PointF(pCenter.X