C#GDI绘图编程
C#中饼图可用单色刷绘制,如何将构成饼图的每个扇形分别用不同的画刷(如:网络、渐变、纹理刷)填充?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace 饼图
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
this.Refresh();
int boynum = int.Parse(textBox1.Text);
int girlnum = int.Parse(textBox2.Text);
float boy = (float) boynum / (boynum + girlnum);
float girl = (float) girlnum / (boynum + girlnum);
SolidBrush sb1 = new SolidBrush(Color.Blue);
SolidBrush sb2 = new SolidBrush(Color.Red);
Rectangle rect=new Rectangle(20,80,80,80);
g.FillPie(sb1, rect, 0, -boy * 360);
g.FillPie(sb2, rect, -boy * 360, -girl * 360);
Font f=new Font("宋体",10,FontStyle.Bold);
Point pt1=new Point(130,100);
Point pt2=new Point(130,120);
boy = (float)Math.Round(boy * 100, 2);
girl= (float) Math.Round(girl * 100, 2);
g.DrawString("男 = " + boy.ToString()+"%", f, sb1, pt1);
g.DrawString("女 = " + girl.ToString()+"%", f, sb2, pt2);
sb1.Dispose();
sb2.Dispose();
g.Dispose();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace 饼图
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
this.Refresh();
int boynum = int.Parse(textBox1.Text);
int girlnum = int.Parse(textBox2.Text);
float boy = (float) boynum / (boynum + girlnum);
float girl = (float) girlnum / (boynum + girlnum);
SolidBrush sb1 = new SolidBrush(Color.Blue);
SolidBrush sb2 = new SolidBrush(Color.Red);
Rectangle rect=new Rectangle(20,80,80,80);
g.FillPie(sb1, rect, 0, -boy * 360);
g.FillPie(sb2, rect, -boy * 360, -girl * 360);
Font f=new Font("宋体",10,FontStyle.Bold);
Point pt1=new Point(130,100);
Point pt2=new Point(130,120);
boy = (float)Math.Round(boy * 100, 2);
girl= (float) Math.Round(girl * 100, 2);
g.DrawString("男 = " + boy.ToString()+"%", f, sb1, pt1);
g.DrawString("女 = " + girl.ToString()+"%", f, sb2, pt2);
sb1.Dispose();
sb2.Dispose();
g.Dispose();
}
}
}
...全文


