using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D;namespace Test { public partial class frmMain : Form { const int DrawStep = 20; public frmMain() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } protected override void OnPaint(PaintEventArgs e) { Pen myPen = new Pen(Color.Red, 1); myPen.EndCap = LineCap.ArrowAnchor; e.Graphics.DrawLine(myPen, 30, this.Height / 2, this.Width-30, this.Height / 2); e.Graphics.DrawLine(myPen, this.Width/2, this.Height-20, this.Width/2,20);
int ndrawCount = Width / (2*DrawStep); // Create string to draw. String drawString = ""; SolidBrush drawBrush = new SolidBrush(Color.Black); for (int i = 1; i < ndrawCount-1; ++i) { drawString = i.ToString(); e.Graphics.DrawLine(myPen, Width / 2 + DrawStep * i, this.Height / 2, Width / 2 + DrawStep * i, this.Height / 2 - 3); // Create font and brush. Font drawFont = new Font("Arial", 12); // Create point for upper-left corner of drawing. PointF drawPoint = new PointF(Width / 2 + DrawStep * i-8, this.Height / 2+1); // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint); } base.OnPaint(e); } }由于时间仓促写了点,可以看到X轴正方向有坐标和数字标注了
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace Test
{
public partial class frmMain : Form
{
const int DrawStep = 20;
public frmMain()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
}
protected override void OnPaint(PaintEventArgs e)
{
Pen myPen = new Pen(Color.Red, 1);
myPen.EndCap = LineCap.ArrowAnchor;
e.Graphics.DrawLine(myPen, 30, this.Height / 2, this.Width-30, this.Height / 2);
e.Graphics.DrawLine(myPen, this.Width/2, this.Height-20, this.Width/2,20);
int ndrawCount = Width / (2*DrawStep);
// Create string to draw.
String drawString = "";
SolidBrush drawBrush = new SolidBrush(Color.Black); for (int i = 1; i < ndrawCount-1; ++i)
{
drawString = i.ToString();
e.Graphics.DrawLine(myPen,
Width / 2 + DrawStep * i,
this.Height / 2,
Width / 2 + DrawStep * i,
this.Height / 2 - 3);
// Create font and brush.
Font drawFont = new Font("Arial", 12);
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(Width / 2 + DrawStep * i-8, this.Height / 2+1);
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint); }
base.OnPaint(e);
}
}由于时间仓促写了点,可以看到X轴正方向有坐标和数字标注了