Thứ Tư, 1 tháng 4, 2009

Tạo biểu đồ xem dung lượng ổ cứng

Bài viết này hướng dẫn bạn cách tạo ra một ứng dụng biểu đồ dùng để hiện thị dung lượng của các ổ cứng như thế nào. Các namespace được sử dụng như sau: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System...

Bài viết này hướng dẫn bạn cách tạo ra một ứng dụng biểu đồ dùng để hiện thị dung lượng của các ổ cứng như thế nào.

Các namespace được sử dụng như sau:

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Windows.Forms;
  7. using System.Data;

Các cấu trúc sử dụng:

  1. struct MyDirTotalSize
  2. {
  3. public string dirPath;
  4. public long totalSize;
  5. public int parent;
  6. }
  7. struct MyAngleStruct
  8. {
  9. public string folderpath;
  10. public float myAngle;
  11. public long mySize;
  12. }

Hàm dưới đây đảm nhiệm việc tạo ra các góc cho mỗi đường dẫn thư mục:

  1. private void GeneratePieChartAngle(string path)
  2. {
  3. MyAngleStruct angStructObj;
  4. angStructObj.myAngle = 0;
  5. MyDirTotalSize eff;
  6. long opteller = 0, compsize = 0;
  7. int startingPoint = -1, startingPoint2;
  8. for (startingPoint2 = 0; startingPoint2 <>
  9. {
  10. eff = (MyDirTotalSize) (SizeDir[startingPoint2]);
  11. if (path != eff.dirPath) continue;
  12. compsize += eff.totalSize;
  13. angStructObj.folderpath = eff.dirPath;
  14. angStructObj.mySize = eff.totalSize;
  15. AngleS.Add(angStructObj);
  16. startingPoint = eff.parent;
  17. }
  18. foreach (MyDirTotalSize ef in SizeDir)
  19. {
  20. if (ef.dirPath.CompareTo(path) == 0 || startingPoint <>continue;
  21. if (!ef.dirPath.StartsWith(path)) continue;
  22. compsize += ef.totalSize;
  23. startingPoint2 = ef.parent;
  24. opteller += ef.totalSize;
  25. if (startingPoint2 > (startingPoint + 1)) continue;
  26. angStructObj.folderpath = ef.dirPath;
  27. angStructObj.mySize = opteller;
  28. AngleS.Add(angStructObj);
  29. opteller = 0; //ef.size;
  30. }
  31. startingPoint = AngleS.Count;
  32. for (startingPoint2 = 0; startingPoint2 <>
  33. {
  34. angStructObj = (MyAngleStruct) (AngleS[startingPoint2]);
  35. AngleS.RemoveAt(startingPoint2);
  36. angStructObj.myAngle = (angStructObj.mySize/(float) compsize)*360;
  37. AngleS.Insert(startingPoint2, angStructObj);
  38. }
  39. }

Vẽ các góc biểu đồ hình tròn từ các vị trí bắt đầu và kết thúc

  1. private void DrawPitotal1romAngles()
  2. {
  3. float realAngle=0F;
  4. Random rnd = new Random();
  5. Red=Green=Blue=0;
  6. pas.Clear(BackColor);
  7. foreach(MyAngleStruct total1 in AngleS)
  8. {
  9. pas.FillPie(brus,rRect,realAngle,total1.myAngle);realAngle+=total1.myAngle;
  10. //Generate random color for drawing
  11. int myRed = myGreen = myBlue = Random() % 250;
  12. brus.Color = System.Drawing.Color.FromArgb(myRed,myGreen,myBlue);
  13. }
  14. }

Kết quả thu được như sau:

2 nhận xét:

  1. Lưu ý các bài viết của bạn cần nêu rõ nguồn lấy từ đâu!!!

    Trả lờiXóa
  2. http://hp-aptech.edu.vn/hpa/programming/archive/2009/01/22/t-o-bi-u-xem-dung-l-ng-c-ng.aspx

    Trả lờiXóa