资源简介
C# 先检测出指定磁盘的容量,然后根据已使用情况动态生成圆饼图表,就像Windows磁盘属性内的图表一样,直观简洁。你知道用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;
//download by http://www.codefans.net
using System.Management;
using System.IO;
namespace Case09_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
SelectQuery selectQuery = new SelectQuery(“select * from win32_logicaldisk“);
ManagementobjectSearcher searcher = new ManagementobjectSearcher(selectQuery);
foreach (Managementobject disk in searcher.Get())
{
comboBox1.Items.Add(disk[“Name“].ToString());
}
}
private void button1_Click(object sender EventArgs e)
{
DriveInfo dinfo = new DriveInfo(comboBox1.Text);
float tsize = dinfo.TotalSize;
float fsize = dinfo.TotalFreeSpace;
Graphics graphics = this.CreateGraphics();
graphics.Clear(Color.White);
Pen pen1 = new Pen(Color.Red);
Brush brush1 = new SolidBrush(Color.WhiteSmoke);
Brush brush2 = new SolidBrush(Color.Red );
Brush brush3 = new SolidBrush(Color.SteelBlue );
Font font1 = new Font(“Courier New“ 16 Fontstyle.Bold);
Font font2 = new Font(“宋体“ 9);
graphics.DrawString(“磁盘容量分析“ font1 brush2 new Point(60 50));
float angle1 = Convert.ToSingle((360 * (Convert.ToSingle(fsize / 100000000000) / Convert.ToSingle(tsize / 100000000000))));
float angle2 = Convert.ToSingle((360 * (Convert.ToSingle((tsize - fsize) / 100000000000) / Convert.ToSingle(tsize / 100000000000))));
graphics.FillPie(brush2 60 80 150 150 0 angle1);
graphics.FillPie(brush3 60 80 150 150 angle1 angle2);
graphics.DrawRectangle(pen1 30 235 200 50);
graphics.FillRectangle(brush2 35 245 20 10);
graphics.DrawString(“磁盘剩余容量:“ + dinfo.TotalFreeSpace / 1000 + “KB“ font2 brush2 55 245);
graphics.FillRectangle(brush3 35 265 20 10);
graphics.DrawString(“磁盘已用容量:“ + (dinfo.TotalSize - dinfo.TotalFreeSpace) / 1000 + “KB“ font2 brush3 55 265);
}
private void button2_Click(object sender EventArgs e)
{
this.Close();
Application.Exit(); //退出程序
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
----------- --------- ---------- ----- ----
44110 16
- 上一篇:LL1 语法分析器 C#
- 下一篇:c# 上位机 数据波形显示 程序
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论