111,094
社区成员




public partial class Form1 : Form {
public Form1() {
InitializeComponent();
g = this.panel_Canvas.CreateGraphics();//放构造函数或者btn_Start_Click里面都可以
}
int x, y;
Graphics g = null;
List<Point> pList = new List<Point>();//数组有界,这里更应该使用List
private void timer_Draw_Tick(object sender, EventArgs e) {
Random r = new Random();
x = r.Next(0, panel_Canvas.Width);
y = r.Next(1, panel_Canvas.Height);
pList.Add(new Point(x, y));
Pen redPen = new Pen(Brushes.Red);
if (pList.Count > 1) {
//这一句你应该能理解是什么意思
g.DrawLine(redPen, pList[pList.Count - 2], pList[pList.Count -1]);
}
}
private void btn_Start_Click(object sender, EventArgs e) {
timer_Draw.Enabled = true;
}
}