I'm trying to display the size of the hard disk space in a progress bar. I already have the sizes show in the progress bar but i'm confused on whether how i am able to display if it would be 'MB,KB,GB,TB' corresponding to the size shown and etc..
So far this is the code i got
private void Form1_Load(object sender, EventArgs e)
{
foreach (DriveInfo dir in DriveInfo.GetDrives())
cmbDrive.Items.Add(dir.ToString());
}
private void cmbDrive_SelectedIndexChanged(object sender, EventArgs e)
{
DriveInfo Drive_Info = new System.IO.DriveInfo(cmbDrive.Text);
const int byteConversion = 1024;
double bytes = Convert.ToDouble(Drive_Info.TotalSize);
double tSpace = Drive_Info.TotalSize;
double uSpace;
uSpace = Drive_Info.TotalSize - Drive_Info.TotalFreeSpace;
uSpace = Math.Round((uSpace / 1024f) / 1024f / 1024f);
tSpace = Math.Round((tSpace / 1024f) / 1024f / 1024f);
double space = Drive_Info.TotalSize;
double fSpace = Drive_Info.TotalFreeSpace;
prgSpace.Minimum = 0;
prgSpace.Maximum = 100;
prgSpace.Value = (int)Math.Round(100d / tSpace * uSpace);
prgSpace.CreateGraphics().DrawString(uSpace.ToString() + " Free" + " of " + tSpace.ToString() + " ", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(prgSpace.Width / 2 - 10, prgSpace.Height / 2 - 7));