我對c#系統繪製非常新,所以請在我的代碼上幫助我。我試圖繪製二次方程曲線,並使用「for」循環以便爲曲線點10個座標。我已經多次測試過這段代碼,並且在我啓動代碼時什麼都沒有出現。此外,無論何時我運行代碼,我得到的消息ArgumentException是未處理的,參數是無效的代碼「g.DrawCurve(aPen,Points);」突出顯示。請幫助我解決這個問題,我花了很多時間嘗試修復。在c中繪製二次方程曲線#
{
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();
}
開始與畫線與**兩次與固定/常數/未計算出的座標點**。 – DrKoch 2015-02-09 08:02:41