日期:2014-05-20  浏览次数:20904 次

请问C#中怎么画(由X轴和Y轴组成的)数轴?
我想用C#显示出数轴,并在上面画出几个点.

------解决方案--------------------
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(Pens.Black, new Point(0, ClientSize.Height / 2),
new Point(ClientSize.Width, ClientSize.Height / 2));
e.Graphics.DrawLine(Pens.Black, new Point(ClientSize.Width / 2, 0),
new Point(ClientSize.Width / 2, ClientSize.Height));

//todo : 其他绘制
}

------解决方案--------------------
Draw Point(x,y)
------解决方案--------------------
可以用Graphic来绘,可以参看msdn中关于graphic的用法,如果图形复杂的话,可以考虑第三方控件,参见
http://blog.csdn.net/tjvictor/archive/2006/11/24/1412546.aspx

------解决方案--------------------
将代码放到Form1的Paint事件里执行

private void button1_Click(object sender, EventArgs e)
{
Graphics vGraphics = Graphics.FromHwnd(Handle);
vGraphics.DrawLine(Pens.Black, new Point(0, ClientSize.Height / 2),
new Point(ClientSize.Width, ClientSize.Height / 2));
vGraphics.DrawLine(Pens.Black, new Point(ClientSize.Width / 2, 0),
new Point(ClientSize.Width / 2, ClientSize.Height));
}

简单来说就是通过Graphics类的DrawLine()方法绘制直线