我对 c# System Draw 很陌生,所以请帮我处理我的代码。我正在尝试绘制二次方程曲线并使用“for”循环来为曲线点 10 个坐标。我已经多次测试了这段代码,当我启动代码时什么都没有出现。此外,每当我运行代码时,我都会收到消息 ArgumentException was Unhandled, Parameter is not valid with the code "g.DrawCurve(aPen, Points);" 突出显示。请帮助我解决这个问题,我花了很多天试图解决这个问题。
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
float a = 10, b = 30, c = 10;
double x1, x2, delta, cx1, cx2, y1, y2;
int icx1, iy1, icx2, iy2;
delta = (b * b) - (4 * a * c);
x1 = ((b * (-1)) + Math.Sqrt(delta)) / (2 * a);
x2 = ((b * (-1)) - Math.Sqrt(delta)) / (2 * a);
for (int i = (-10); i <= 10; i = i + 1)
{
cx1 = i * x1;
cx2 = i * x2;
y1 = (cx1 * cx1 * a) + (cx1 * b) + c;
y2 = (cx2 * cx2 * a) + (cx2 * b) + c;
icx1 = Convert.ToInt32(cx1);
iy1 = Convert.ToInt32(y1);
icx2 = Convert.ToInt32(cx2);
iy2 = Convert.ToInt32(y2);
Graphics g = e.Graphics;
Pen aPen = new Pen(Color.Blue, 1);
Point point1 = new Point(icx1, iy1);
Point point2 = new Point(icx2, iy2);
Point[] Points = { point1,point2 };
g.DrawCurve(aPen, Points);
aPen.Dispose();
g.Dispose();
}