我让Point数组指定某个点,但我无法在for循环中访问它们。请问有什么可以帮助我?我不能使用Point [] for循环
Point[] _points;
private Point[] Points()
{
Rectangle rc = ClientRectangle;
Point[] _points=new Point[]
{
new Point{X=0,Y=ClientRectangle.Height/2},
new Point{X=ClientRectangle.Width*22/277,Y=0},
new Point{X=ClientRectangle.Width*68/277,Y=ClientRectangle.Height},
new Point{X=ClientRectangle.Width*115/277,Y=0},
new Point{X=ClientRectangle.Width*161/277,Y=ClientRectangle.Height},
new Point{X=ClientRectangle.Width*206/277,Y=0},
new Point{X=ClientRectangle.Width*254/277,Y=ClientRectangle.Height},
new Point{X=ClientRectangle.Width,Y=ClientRectangle.Height/2}
};
return _points;
}
protected override void OnPaint(PaintEventArgs pe)
{
Graphics gfx = pe.Graphics;
Pen kalem = new Pen(Color.Black);
for (int i = 0; i < _points.Length; i++)
{
gfx.DrawLine(kalem,_points[i],_points[i].Y); =======>>>ERROR HERE
}
}
你得到的错误是什么? – craig1231 2014-12-04 12:54:32
更多关注错误(你应该包括在你的问题中)告诉你什么。你忽略了一些非常明显的东西。 – hvd 2014-12-04 12:54:34
你在'OnPaint()'函数之前调用'Points()'函数吗? – Sander 2014-12-04 12:55:07