次の方法で共有


方法 : .NET Framework を使用して形状を描画する

更新 : 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 );
}

参照

参照

System::Drawing 名前空間

その他の技術情報

.NET プログラミング ガイド