guoguogis

  :: :: 新随笔 :: :: :: 管理 ::

private void button3_Click(object sender, System.EventArgs e)
  {//显示根信息
   if(this.textBox1.Text.Trim()=="")
    return;
   string MyRoot=System.IO.Directory.GetDirectoryRoot(this.textBox1.Text);
   MessageBox.Show("根是:"+MyRoot,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

  }

  private void button4_Click(object sender, System.EventArgs e)
  {//显示父目录信息
   if(this.textBox1.Text.Trim()=="")
    return;
   try
   {
    System.IO.DirectoryInfo MyInfo=System.IO.Directory.GetParent(this.textBox1.Text);   
    MessageBox.Show("父目录是:"+MyInfo.FullName,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);  
   }
   catch(Exception Err)
   {
    MessageBox.Show("不要只选择根目录!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
   }
  }

FolderBroserDialoge的用法:
private void button1_Click(object sender, EventArgs e)
        {
            //第一步:判断是否点击了对话框中的确定按钮
            if(this.folderBrowserDialog1.ShowDialog()==DialogResult.OK)
            {
                //第二步:判断选择的路径是否为空
                if(this.folderBrowserDialog1.SelectedPath.Trim()!="")
                {
                    this.textBox1.Text = this.folderBrowserDialog1.SelectedPath.Trim();
                }
            }
        }

posted on 2009-08-28 00:06  guoguogis  阅读(247)  评论(0)    收藏  举报