更新 : 2007 年 11 月
Graphics クラスを使用して OnPaint イベント ハンドラを修正し、メイン フォームの Graphics オブジェクトへのポインタを取得するコード例を次に示します。その後、このポインタを使用して、フォームの背景色を設定し、Graphics.DrawLine メソッドおよび DrawArc メソッドを使用して直線と楕円を描画します。
![]() |
---|
Windows XP には GDI+ が含まれています。また、Windows NT 4.0 SP 6、Windows 2000、Windows 98、および Windows Me 対応の再頒布可能な GDI+ も用意されています。最新の再頒布可能パッケージをダウンロードするには、https://go.microsoft.com/fwlink/?linkid=11232 を参照してください。詳細については、「GDI+」を参照してください。 |
使用例
#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
// ...
protected:
Void Form1::OnPaint(PaintEventArgs^ pe )
{
Graphics^ g = pe->Graphics;
g->Clear(Color::AntiqueWhite);
Rectangle rect = Form::ClientRectangle;
Rectangle smallRect;
smallRect.X = rect.X + rect.Width / 4;
smallRect.Y = rect.Y + rect.Height / 4;
smallRect.Width = rect.Width / 2;
smallRect.Height = rect.Height / 2;
Pen^ redPen = gcnew Pen(Color::Red);
redPen->Width = 4;
g->DrawLine(redPen, 0, 0, rect.Width, rect.Height);
Pen^ bluePen = gcnew Pen(Color::Blue);
bluePen->Width = 10;
g->DrawArc( bluePen, smallRect, 90, 270 );
}