분노의 챔질

[C#] 드라이브 정보보기 DriveInfo 본문

Programming/C#

[C#] 드라이브 정보보기 DriveInfo

분노의블로그 2010. 3. 23. 10:43
반응형



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.IO;

 

namespace CPUUsage

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

            DriveInfo[] drv = DriveInfo.GetDrives();

            int y = 20;

            foreach (DriveInfo d in drv)

            {

                if (d.DriveType == DriveType.Fixed)

                {

                    ProgressBar pb = new ProgressBar();

                    pb.Maximum = Convert.ToInt32(d.TotalSize / 1024 / 1024);

                    pb.Value = Convert.ToInt32(d.AvailableFreeSpace / 1024 / 1024);

                    pb.Size = new Size(145, 20);

                    pb.Location = new Point(10, y);

                    this.Controls.Add(pb);

                    y = y + 22;

 

                    Label l = new Label();

                    l.Name = "l" + y.ToString();

                    l.Text = d.Name + " " + (d.TotalFreeSpace / 1024 / 1024) + "MB Free";

                    l.AutoSize = true;

                    l.Location = new Point(10, y);

                    this.Controls.Add(l);

                    y = y + 20;

                }

            }

        }

    }

}

 

반응형

'Programming > C#' 카테고리의 다른 글

C# 쓰레드 이야기 by 한동훈  (0) 2010.05.27
[C#] 요일구하기  (1) 2010.03.26
[C#] CPU 사용량 보기  (1) 2010.03.23
[C#] 붙여넣기, Ctrl+V  (0) 2010.03.09
[C#] 간단한 UserControl  (0) 2010.03.05