C#GDI绘图编程

czjasasas czjasasas 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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();
}
}
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
czjasasas
C# 111,129 成员 642,538 内容