Visual Studio 2008 Express Edition でグラフを書いてみよう
簡単な2次曲線を描きます。
つづき
}
#pragma endregion
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
ここにプログラムを書く
}
絵の設定 Graphics^ g=e->Graphics;
線を引く g->DrawLine(Pens::Red,はじめx,はじめy,おわりx,おわりy);
具体例
#pragma endregion private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics^ g=e->Graphics;
int xm,ym;
int xs,ys;
int xe,ye;
int x,y;
xm=210;
ym=410;
xs=xm-200;
ys=ym-400;
for (x=-20;x<=20;x++){
y=x*x;
xe=xm-x*10;
ye=ym-y;
g->DrawLine(Pens::Red,xs,ys,xe,ye);
xs=xe;
ys=ye;
}
}
};
}
実行
結果


