資源簡介
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# 上位機 數據波形顯示 程序
評論
共有 條評論