我讓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