1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| private void ShowPic(string SexCode, float f) { this.Controls.Add(panel1); panel1.Width = 230; panel1.Height = 230; bt = new Bitmap(panel1.Width, panel1.Height); Graphics g = Graphics.FromImage(bt); Pen p = new Pen(new SolidBrush(Color.Blue)); Point p1 = new Point(0, 0); Size s = new Size(this.panel1.Width, this.panel1.Height); Rectangle trct = new Rectangle(p1, s); g.FillEllipse(new SolidBrush(Color.Red), trct); g.FillPie(new SolidBrush(Color.Blue), trct, flag, f * 360); bt1 = new Bitmap(panel2.Width, panel2.Height); Graphics ginfo = Graphics.FromImage(bt1); Font font = new Font("宋体", 10, FontStyle.Regular); ginfo.DrawString(SexCode + " " + f.ToString().Substring(0, 4), font, new SolidBrush(Color.Blue), 0, 5); ginfo.DrawString("女" + " " + (1.0 - Convert.ToDouble(f.ToString().Substring(0, 4))).ToString().Substring(0, 4), font, new SolidBrush(Color.Red), 0, 25); panel1.BackgroundImage = bt; panel2.BackgroundImage = bt1; } private void button1_Click(object sender, EventArgs e) { Conn(); using (cmd = new SqlCommand("SELECT sex,COUNT(sex) num FROM tb_sex group by sex", con)) { SqlDataReader dr = cmd.ExecuteReader(); string[] str = new string[2]; int i = 0; while (dr.Read()) { str[i] = dr[0].ToString() + "," + dr[1].ToString(); i++; } float N = Convert.ToInt16(str[0].Substring(2)) + Convert.ToInt16(str[1].Substring(2)); float f = Convert.ToInt16(str[0].Substring(2)) / N; flag = 180; ShowPic(str[0].Substring(0, 1), f); } con.Close(); } private void timer1_Tick(object sender, EventArgs e) { flag += 1; Conn(); using (cmd = new SqlCommand("SELECT sex,COUNT(sex) num FROM tb_sex group by sex", con)) { SqlDataReader dr = cmd.ExecuteReader(); string[] str = new string[2]; int i = 0; while (dr.Read()) { str[i] = dr[0].ToString() + "," + dr[1].ToString(); i++; } float N = Convert.ToInt16(str[0].Substring(2)) + Convert.ToInt16(str[1].Substring(2)); float f = Convert.ToInt16(str[0].Substring(2)) / N; ShowPic(str[0].Substring(0, 1), f); } con.Close(); } private void button2_Click(object sender, EventArgs e) { if (button2.Text == "旋转") { timer1.Start(); button2.Text = "停止"; } else { timer1.Stop(); button2.Text = "旋转"; } }
|