Visual C#2005 文件IO 第一章第二节
来源:互联网 发布:淘宝店智能版怎么装修 编辑:程序博客网 时间:2024/06/09 19:48
//选中磁盘驱动器信息再RichBox控件和DataGridview控件中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TestDriveInfo
...{
public partial class Form1 : Form
...{
public partial class frmStatus : Form
...{
public void Show(string Message)
...{
Application.DoEvents();
}
}
public Form1()
...{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
...{
//显示一个状态信息框来表示目前要尝试取得计算机的磁盘信息
frmStatus frmStatusMessage = new frmStatus();
frmStatusMessage.Show(“处理中,请稍后.......”);
StringBuilder sb = new StringBuilder();//可变字符串
DriveInfo[] myAllDrives = DriveInfo.GetDrives();
try
...{
foreach (DriveInfo myDrive in myAllDrives)
...{
//使用IsReady属性判断磁盘设备是否就绪
if (myDrive.IsReady)
...{
sb.Append("磁盘驱动器符:");
sb.AppendLine(myDrive.Name);
sb.Append("磁盘卷符:");
sb.AppendLine(myDrive.VolumeLabel);
sb.Append("磁盘类型:");
sb.AppendLine(myDrive.DriveType.ToString());
sb.Append("磁盘的大小:");
sb.AppendLine(myDrive.TotalSize.ToString());
sb.Append("磁盘剩余空间:");
sb.AppendLine(myDrive.TotalFreeSpace.ToString());
sb.Append("总剩余空间(含磁盘配额):");
sb.AppendLine(myDrive.AvailableFreeSpace.ToString());
sb.AppendLine("---------------------------------------");
}
}
}
catch(Exception ex)
...{
MessageBox.Show(ex.Message);
}
frmStatusMessage.Close();
this.richTextBox1.Text = sb.ToString();
//显示于DataGridView控件中
//this.dataGridView1.DataError+=new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
this.dataGridView1.DataSource = DriveInfo.GetDrives();
}
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
...{
}
private void Form1_Load(object sender, EventArgs e)
...{
DriveInfo[] myAllDriveInfo = DriveInfo.GetDrives();
this.comboBox1.Items.AddRange(myAllDriveInfo);
}
//combox控件选中事件
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
...{
DriveInfo theDriveInfo=(DriveInfo)comboBox1.Items[comboBox1.SelectedIndex];
if (theDriveInfo.IsReady)
...{
this.propertyGrid1.SelectedObject = comboBox1.Items[comboBox1.SelectedIndex];
}
else
...{
MessageBox.Show(theDriveInfo.Name+"磁盘尚未就绪","请注意",MessageBoxButtons.OK);
this.propertyGrid1.SelectedObject = null;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TestDriveInfo
...{
public partial class Form1 : Form
...{
public partial class frmStatus : Form
...{
public void Show(string Message)
...{
Application.DoEvents();
}
}
public Form1()
...{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
...{
//显示一个状态信息框来表示目前要尝试取得计算机的磁盘信息
frmStatus frmStatusMessage = new frmStatus();
frmStatusMessage.Show(“处理中,请稍后.......”);
StringBuilder sb = new StringBuilder();//可变字符串
DriveInfo[] myAllDrives = DriveInfo.GetDrives();
try
...{
foreach (DriveInfo myDrive in myAllDrives)
...{
//使用IsReady属性判断磁盘设备是否就绪
if (myDrive.IsReady)
...{
sb.Append("磁盘驱动器符:");
sb.AppendLine(myDrive.Name);
sb.Append("磁盘卷符:");
sb.AppendLine(myDrive.VolumeLabel);
sb.Append("磁盘类型:");
sb.AppendLine(myDrive.DriveType.ToString());
sb.Append("磁盘的大小:");
sb.AppendLine(myDrive.TotalSize.ToString());
sb.Append("磁盘剩余空间:");
sb.AppendLine(myDrive.TotalFreeSpace.ToString());
sb.Append("总剩余空间(含磁盘配额):");
sb.AppendLine(myDrive.AvailableFreeSpace.ToString());
sb.AppendLine("---------------------------------------");
}
}
}
catch(Exception ex)
...{
MessageBox.Show(ex.Message);
}
frmStatusMessage.Close();
this.richTextBox1.Text = sb.ToString();
//显示于DataGridView控件中
//this.dataGridView1.DataError+=new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
this.dataGridView1.DataSource = DriveInfo.GetDrives();
}
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
...{
}
private void Form1_Load(object sender, EventArgs e)
...{
DriveInfo[] myAllDriveInfo = DriveInfo.GetDrives();
this.comboBox1.Items.AddRange(myAllDriveInfo);
}
//combox控件选中事件
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
...{
DriveInfo theDriveInfo=(DriveInfo)comboBox1.Items[comboBox1.SelectedIndex];
if (theDriveInfo.IsReady)
...{
this.propertyGrid1.SelectedObject = comboBox1.Items[comboBox1.SelectedIndex];
}
else
...{
MessageBox.Show(theDriveInfo.Name+"磁盘尚未就绪","请注意",MessageBoxButtons.OK);
this.propertyGrid1.SelectedObject = null;
}
}
}
}
- Visual C#2005 文件IO 第一章第二节
- Visual C#2005 文件IO 第一章第一节
- 第一章 文件IO的操作
- 第一章 -- 第二节
- 【第一章 第二节】
- 【第一章 第二节】
- 评《Visual Basic 2005 文件IO与数据存取秘诀》
- Visual+C#+2005文件IO和数据存取秘诀 目录
- C#文件IO操作
- C#文件IO操作
- C# 文件处理IO
- Java学习第一章 第二节
- 《Visual C# 最佳实践》第一章 程序设计 (一):程序概念
- 《Visual C# 最佳实践》第一章 程序设计 (二):数据类型
- 《Visual C# 最佳实践》第一章 程序设计 (三):变量
- 《Visual C# 最佳实践》第一章 程序设计 (四):运算符
- Visual C# 技术内幕学习笔记 第一章 简介
- Visual C# 生成DLL文件
- redhat 9中默认的vsftpd服务器配置小心得
- Java I/O (一)文件类 java.io.File
- JavaScript弹出模式窗口
- JIRA服务器subversion插件的安装问题
- Java I/O (二)流类
- Visual C#2005 文件IO 第一章第二节
- SVN与LDAP的结合,用viewVC浏览
- Java I/O (三)读取和写入文件
- linux运行级init详解
- eclipse shortcuts
- linux 常用指令
- AU1200 BSP的变量未声明错误
- Java I/O (四)缓冲流类
- 用Java实现几种常见的排序算法