using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlClient;namespace Bt
{
    public partial class BtForm : Form
    {
        ArrayList list = new ArrayList();
        SqlCommand cmd;
        SqlConnection con;
        SqlDataReader read;
        public BtForm()
        {
            InitializeComponent();
            con = DB.getCon();
        }        private void BtForm_Load(object sender, EventArgs e)
        {        }        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "select age from students";
            try
            {
                con.Open();
                cmd = new SqlCommand(sql, con);
                read = cmd.ExecuteReader();
                while (read.Read())
                {
                    list.Add(read.GetInt32(0));
                }
                read.Close();
                int[] temp = new int[list.Count];
                list.CopyTo(temp);
                int a = 0; int b = 0; int c = 0; int d = 0;
                int e1 = 0; int f = 0;
                for (int i = 0; i < temp.Length; i++)
                {
                    if (temp[i] >= 0 && temp[i] <= 10)
                    {
                        a++;
                    }
                    if (temp[i] > 10 && temp[i] <= 20)
                    {
                        b++;
                    }
                    if (temp[i] > 20 && temp[i] <= 30)
                    {
                        c++;
                    }
                    if (temp[i] > 30 && temp[i] <= 40)
                    {
                        d++;
                    }
                    if (temp[i] > 40 && temp[i] <= 50)
                    {
                        e1++;
                    }
                    if (temp[i] > 50)
                    {
                        f++;
                    }
                }
                int[] n ={ a, b, c, d, e1, f };
                Graphics g = panel1.CreateGraphics();
                Graphics g2 = panel2.CreateGraphics();
                float jd = 0;
                float count = 0;
                foreach (int m in n)
                {
                    count += m;
                }
                Random r = new Random();
                string[] str = new string[10];
                str[0]="10岁以下有:";
                str[1]="10~20岁有:";
                str[2]="20~30岁有:";
                str[3]="30~40岁有:";
                str[4]="40~50岁有:";
                str[5]="50岁以上有:";
                for (int x = 0; x < n.Length; x++)
                {
                    for (int y = 0; y < str.Length; y++)
                    {
                    Color co = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
                    Brush bsh = new SolidBrush(co);
                    g.FillPie(bsh, 20, 20, 300, 300, jd, n[x] / count * 360);
                    g2.FillRectangle(bsh, 20, 40 * (x + 1), 20, 20);
                    g2.DrawString(str[y] +n[x] + "人", new Font("宋体", 20), bsh, 60,40 * (x+1));
                    jd += n[x] / count * 360;
                    //MessageBox.Show(jd.ToString());
               }               }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                con.Close();
            }
        }
    }
}
请高手帮我看下 我的FOR写的是不是有问题
在PANEL2中显示字体做了两遍貌似