专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C#

为什么获取不到Windows操作系统的盘符?该怎么解决

发布时间:2011-06-21 11:33:17 文章来源:www.iduyao.cn 采编人员:星星草
为什么获取不到Windows操作系统的盘符?
大家好,帮我看下下面这段代码,是教程书上的一个例子,说运行起来可以获取到Windows操作系统的盘符,如C:,D:,E:等。
但是我调试起来,Windows窗体是空的,没有显示Windows操作系统的盘符,这是为什么?我的操作系统是Windows7旗舰版,用的是VS2005。
先在这里谢谢了!
代码如下:

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 test
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }
  private void Form1_Load(object sender, EventArgs e)
  {
  string[] drives = Directory.GetLogicalDrives();
  for (int i = 0; i < drives.Length; i++)
  {
  listBox1.Items.Add ( drives[i]);
  }
  }
  }
}


------解决方案--------------------
帮你顶 下…………
------解决方案--------------------
同样的代码我这里是成功的
------解决方案--------------------
代码没问题,打断点跟踪一下...

也可以用这个...

DriveInfo[] drives = DriveInfo.GetDrives();

还可以用这个...

string[] drives = Environment.GetLogicalDrives();
------解决方案--------------------
看看窗体属性,点小闪电标志。看Form1_Load事件是不是没注册上,在Form1_Load事件中加断点,看是否执行过。
------解决方案--------------------
测试过可以的,设断点调试下吧~
C# code

string[] GetLogicDir = Directory.GetLogicalDrives();
            foreach (string dir in GetLogicDir)
            {
                listBox1.Items.Add(dir);
            }
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: