using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace testdraw
{
    public partial class Form1 : Form
    {
        protected Bitmap cBmp = new Bitmap(200, 200); //创建画布
        protected Graphics cGraphic;
        protected Color[] cColor = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Gray, Color.LightCoral, Color.Gold };
        protected Pen cPen;
        protected SolidBrush cSolidBrush;
        protected Point[] cPoints;
        protected int RowNum = 3; //扇区块数
        protected int i = 0;
        protected int j = 0;
        protected int cAngle = 0;
        protected int tmp = 0;
        protected int xCircleCenter = 100;
        protected int yCircleCenter = 100;        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                cGraphic = Graphics.FromImage(cBmp);
                cGraphic.Clear(Color.Snow);                for (j = 0; j < RowNum; j++)
                {
                    cAngle = 90;//扇区角度
                    cPen = new Pen(cColor[j], 3);
                    cSolidBrush = new SolidBrush(cColor[j]);
                    for (i = tmp; i < tmp + cAngle; i++)
                    {
                        cPoints[i - tmp] = new Point();
                        cPoints[i - tmp].X = (int)(1 - System.Math.Sin(i / 360 * 2 * System.Math.PI)) * (xCircleCenter - 30) + 10;
                        cPoints[i - tmp].Y = (int)(1 - System.Math.Cos(i / 360 * 2 * System.Math.PI)) * (yCircleCenter - 30) + 10;                    }
                    //加入圆心坐标点
                    cPoints[cAngle + 1] = new Point();
                    cPoints[cAngle + 1].X = xCircleCenter - 20;
                    cPoints[cAngle + 1].Y = yCircleCenter - 20;                    cPen = new Pen(cColor[j], 3);
                    cSolidBrush = new SolidBrush(cColor[j]);
                    cGraphic.DrawPolygon(cPen, cPoints);
                    cGraphic.FillPolygon(cSolidBrush, cPoints);
                    tmp += cAngle;
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
            pictureBox1.Image = cBmp;
        }
    }
}

解决方案 »

  1.   

     protected Point[] cPoints   的cPoints  没有new
      

  2.   

     cPoints[i - tmp] = new Point(); 
    提示这句有问题,"未将对象引用设置到对象的实例"
      

  3.   

    cPoints[i - tmp] = new Point();  cPoints是一个Point数组。初始化
     cPoints[i - tmp]=new Point[i - tmp];
      

  4.   

    这样改
                    cGraphic = Graphics.FromImage(cBmp); 
                    cGraphic.Clear(Color.Snow);                cAngle = 90;//扇区角度 
                    cPoints = new Point[cAngle * RowNum];                for (j = 0; j  < RowNum; j++) 
                    { 
                        cPen = new Pen(cColor[j], 3); 
                        cSolidBrush = new SolidBrush(cColor[j]); 
                        for (i = tmp; i  < tmp + cAngle; i++) 
                        {另外,你这个程序毛病还有很多很多
    比如除法如果是用int来除的话,返回的也是整形
    应该                        
    cPoints[i - tmp].X = (int)(1 - System.Math.Sin((float)i / (float)360) * 2 * System.Math.PI) * (xCircleCenter - 30) + 10;
    还有,圆心和圆周的坐标不要用同一个数组。
    另外你圆周坐标的计算方法也有点问题,数学的问题你自己看看吧。
      

  5.   


                            cPoints[i - tmp].X = (int)((1 - System.Math.Sin((float)i / (float)360 * 2 * System.Math.PI)) * (xCircleCenter - 30)) + 10;
                            cPoints[i - tmp].Y = (int)((1 - System.Math.Cos((float)i / (float)360 * 2 * System.Math.PI)) * (xCircleCenter - 30)) + 10;
    以上是画点的坐标