基本信息
源码名称:c#获取磁盘总容量和剩余容量 示例源码
源码大小:0.19M
文件格式:.zip
开发语言:C#
更新时间:2017-12-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C# 获取硬盘空间信息 盘符总大小、剩余空间、已用空间
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;
namespace GetHardDiskSize
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void Frm_Main_Load(object sender, EventArgs e)
{
System.IO.DriveInfo[] drive = System.IO.DriveInfo.GetDrives();//获取所有驱动器
for (int i = 0; i < drive.Length; i )//遍历驱动器
{
comboBox1.Items.Add(drive[i].Name);//将驱动器添加到下拉列表中
}
comboBox1.SelectedIndex = 0;//设置下拉列表默认选择第一项
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
System.IO.DriveInfo[] drive = System.IO.DriveInfo.GetDrives();//获取所有驱动器
for (int i = 0; i < drive.Length; i )//遍历驱动器
{
if (comboBox1.SelectedItem.ToString() == drive[i].Name)//判断遍历到的项是否与下拉列表中的项相同
{
label1.Text = "总空间:" drive[i].TotalSize / 1024 / 1024 / 1024 "G";//显示总空间
label2.Text = "剩余空间:" drive[i].TotalFreeSpace / 1024 / 1024 / 1024 "G";//显示剩余空间
label3.Text = "已用空间:" (drive[i].TotalSize - drive[i].TotalFreeSpace) / 1024 / 1024 / 1024 "G";//显示已用空间
}
}
}
catch { }
}
}
}