这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Brushes.Blue);
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
float p1x = float.Parse(dr.Cells["p1x"].Value.ToString());
float p1y = float.Parse(dr.Cells["p1y"].Value.ToString());
float p2x = float.Parse(dr.Cells["p2x"].Value.ToString());
float p2y = float.Parse(dr.Cells["p2y"].Value.ToString());
g.DrawEllipse(p, p1x, p1y, 10, 10);
g.DrawEllipse(p, p2x, p2y, 10, 10);
g.FillEllipse(Brushes.Black, p1x, p1y, 10, 10);
g.FillEllipse(Brushes.Black, p2x, p2y, 10, 10);
g.DrawLine(p, p1x, p1y, p2x, p2y);
}
}
在执行上述代码时,我得到运行时异常“对象引用未设置为对象的实例”。请帮忙。