//----------------------------------------------------
// Modified from PieChart.cs  2001 by Charles Petzold
//----------------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;

class PieChart: Form
{
     int[] aiValues = { 50, 100, 25, 150, 100, 75 };

     public new static void Main()
     {
          Application.Run(new PieChart());
     }
     public PieChart()
     {
          Text = "Pie Chart";
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
		  Graphics grfx = pea.Graphics;
		  Color clr = ForeColor;
		  int cx = ClientSize.Width;
		  int cy = ClientSize.Height;
  
		 
		  Rectangle rect   = new Rectangle(50, 50, 200, 200);
          Pen       pen    = new Pen(clr);
          int       iTotal = 0;
          float     fAngle = 0, fSweep;

          foreach(int iValue in aiValues)
               iTotal += iValue;

          foreach(int iValue in aiValues)
          {
               fSweep = 360f * iValue / iTotal;
               DrawPieSlice(grfx, pen, rect, fAngle, fSweep);
               fAngle += fSweep;
          }
     }
     protected virtual void DrawPieSlice(Graphics grfx, Pen pen, 
                                         Rectangle rect,
                                         float fAngle, float fSweep)
     {
          grfx.DrawPie(pen, rect, fAngle, fSweep); 
     }
}
