如何实现一个选择文件路径的对话框? http://expert.csdn.net/Expert/topic/1155/1155973.xml?temp=.0625574 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为什么不用SaveFileDialog 多么简单呀。我就是这么用的。效果很好。 http://www.codeproject.com/cs/miscctrl/folderseldlg.asp 我上边提供的有误。 下面提供另一个:///<summary>///功能名称:表示层选择路径///功能描述:用户在备份过程中,当前空间已满后,选择新路径///作 者:wxf 版本:1.0 ---2002-06-28---///修 改:///</summary>using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace TJJ{ /// <summary> /// 名称:NewPath /// 描述:用户在备份过程中,当前空间已满后,选择新路径 /// 作者:wxf 版本:1.0 ---2002-06-28--- /// 修改: /// </summary> public class NewPath : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.TreeView treeView1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; public string newFilePath; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public NewPath() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.treeView1 = new System.Windows.Forms.TreeView(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(16, 12); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(80, 16); this.label1.TabIndex = 0; this.label1.Text = "请选择路径:"; // // treeView1 // this.treeView1.ImageIndex = -1; this.treeView1.Location = new System.Drawing.Point(36, 36); this.treeView1.Name = "treeView1"; this.treeView1.SelectedImageIndex = -1; this.treeView1.Size = new System.Drawing.Size(356, 304); this.treeView1.TabIndex = 1; this.treeView1.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterExpand); this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); // // button1 // this.button1.Enabled = false; this.button1.Location = new System.Drawing.Point(228, 348); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(68, 24); this.button1.TabIndex = 2; this.button1.Text = "确 定"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(296, 348); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(68, 24); this.button2.TabIndex = 3; this.button2.Text = "取 消"; this.button2.Click += new System.EventHandler(this.button2_Click); // // NewPath // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(424, 385); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button2, this.button1, this.treeView1, this.label1}); this.Name = "NewPath"; this.Text = "NewPath"; this.Load += new System.EventHandler(this.NewPath_Load); this.ResumeLayout(false); } #endregion private void NewPath_Load(object sender, System.EventArgs e) { if(!GetLocalDrivers()) { MessageBox.Show("显示本地驱动器出错!"); return; } } /// <summary> /// 取得本地驱动器,初始化ListView /// </summary> /// <returns>初始化成功返回true</returns> private bool GetLocalDrivers() { try { string[] Drivers=System.IO.Directory.GetLogicalDrives(); treeView1.Nodes.Clear(); System.Windows.Forms.TreeNode rootNode; for(int i=0;i<Drivers.Length;i++) { rootNode=new System.Windows.Forms.TreeNode(Drivers[i]); treeView1.Nodes.Add(rootNode); if(!GetSubDirectory(rootNode.FullPath,rootNode)) { return false; } } return true; } catch { return false; } } /// <summary> /// 取得当前文件夹的子文件夹,并添加为它的子节点 /// </summary> /// <param name="FullPath">当前节点的路径</param> /// <param name="CurrentNode">当前节点</param> /// <returns>操作成功返回true</returns> private bool GetSubDirectory(string FullPath,System.Windows.Forms.TreeNode CurrentNode) { try { CurrentNode.Nodes.Clear(); string myTemp; string[] Directorys=System.IO.Directory.GetDirectories(FullPath); System.Windows.Forms.TreeNode subNode; for(int i=0;i<Directorys.Length;i++) { myTemp=Directorys[i].Remove(0,FullPath.Length); subNode=new System.Windows.Forms.TreeNode(myTemp); CurrentNode.Nodes.Add(subNode); } return true; } catch { return false; } } /// <summary> /// 选中某个节点时,取得当前指定的路径 /// </summary> /// <param name="sender">事件触发者</param> /// <param name="e">时间参数</param> private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { newFilePath=treeView1.SelectedNode.FullPath; button1.Enabled=true; System.Windows.Forms.TreeNodeCollection myNodeCollection=treeView1.SelectedNode.Nodes; foreach( System.Windows.Forms.TreeNode myTreeNode in myNodeCollection) { if(!GetSubDirectory(myTreeNode.FullPath,myTreeNode)) { MessageBox.Show("当前节点展开时,添加子节点出错!"); return; } } treeView1.Update(); } /// <summary> /// 某个节点展开时,给它的子节点增加子节点 /// </summary> /// <param name="sender">事件触发者</param> /// <param name="e">时间参数</param> private void treeView1_AfterExpand(object sender, System.Windows.Forms.TreeViewEventArgs e) { System.Windows.Forms.TreeNodeCollection myNodeCollection=e.Node.Nodes; foreach( System.Windows.Forms.TreeNode myTreeNode in myNodeCollection) { if(!GetSubDirectory(myTreeNode.FullPath,myTreeNode)) { MessageBox.Show("当前节点展开时,添加子节点出错!"); return; } } treeView1.Update(); } /// <summary> /// 取消 /// </summary> /// <param name="sender">事件触发者</param> /// <param name="e">时间参数</param> private void button2_Click(object sender, System.EventArgs e) { newFilePath=""; this.Dispose(); } /// <summary> /// 确定 /// </summary> /// <param name="sender">事件触发者</param> /// <param name="e">时间参数</param> private void button1_Click(object sender, System.EventArgs e) { this.Dispose(); } }} C#有些语句看不懂 如何调用API获得CPU类型? 救助:C#实现打印图像的方法 请问在ACCESS里面怎么获得当前新增记录的ID值? winfrom链接access问题 请问怎样用OleDb运行Oracle存储过程? 最后所有人问一个问题 帮忙看看这个sql怎么改??急急急 求一条正则表达式 有意思的问题。 数据更新的问题! 谁能提供c#目录选择对话框的有关参数?
///功能名称:表示层选择路径
///功能描述:用户在备份过程中,当前空间已满后,选择新路径
///作 者:wxf 版本:1.0 ---2002-06-28---
///修 改:
///</summary>using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace TJJ
{
/// <summary>
/// 名称:NewPath
/// 描述:用户在备份过程中,当前空间已满后,选择新路径
/// 作者:wxf 版本:1.0 ---2002-06-28---
/// 修改:
/// </summary>
public class NewPath : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
public string newFilePath;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public NewPath()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.treeView1 = new System.Windows.Forms.TreeView();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 0;
this.label1.Text = "请选择路径:";
//
// treeView1
//
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(36, 36);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(356, 304);
this.treeView1.TabIndex = 1;
this.treeView1.AfterExpand += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterExpand);
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// button1
//
this.button1.Enabled = false;
this.button1.Location = new System.Drawing.Point(228, 348);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(68, 24);
this.button1.TabIndex = 2;
this.button1.Text = "确 定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(296, 348);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(68, 24);
this.button2.TabIndex = 3;
this.button2.Text = "取 消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// NewPath
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 385);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1,
this.treeView1,
this.label1});
this.Name = "NewPath";
this.Text = "NewPath";
this.Load += new System.EventHandler(this.NewPath_Load);
this.ResumeLayout(false); }
#endregion private void NewPath_Load(object sender, System.EventArgs e)
{
if(!GetLocalDrivers())
{
MessageBox.Show("显示本地驱动器出错!");
return;
}
} /// <summary>
/// 取得本地驱动器,初始化ListView
/// </summary>
/// <returns>初始化成功返回true</returns>
private bool GetLocalDrivers()
{
try
{
string[] Drivers=System.IO.Directory.GetLogicalDrives();
treeView1.Nodes.Clear();
System.Windows.Forms.TreeNode rootNode;
for(int i=0;i<Drivers.Length;i++)
{
rootNode=new System.Windows.Forms.TreeNode(Drivers[i]);
treeView1.Nodes.Add(rootNode);
if(!GetSubDirectory(rootNode.FullPath,rootNode))
{
return false;
}
}
return true;
}
catch
{
return false;
}
} /// <summary>
/// 取得当前文件夹的子文件夹,并添加为它的子节点
/// </summary>
/// <param name="FullPath">当前节点的路径</param>
/// <param name="CurrentNode">当前节点</param>
/// <returns>操作成功返回true</returns>
private bool GetSubDirectory(string FullPath,System.Windows.Forms.TreeNode CurrentNode)
{
try
{
CurrentNode.Nodes.Clear();
string myTemp;
string[] Directorys=System.IO.Directory.GetDirectories(FullPath);
System.Windows.Forms.TreeNode subNode;
for(int i=0;i<Directorys.Length;i++)
{
myTemp=Directorys[i].Remove(0,FullPath.Length);
subNode=new System.Windows.Forms.TreeNode(myTemp);
CurrentNode.Nodes.Add(subNode);
}
return true;
}
catch
{
return false;
}
} /// <summary>
/// 选中某个节点时,取得当前指定的路径
/// </summary>
/// <param name="sender">事件触发者</param>
/// <param name="e">时间参数</param>
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
newFilePath=treeView1.SelectedNode.FullPath;
button1.Enabled=true;
System.Windows.Forms.TreeNodeCollection myNodeCollection=treeView1.SelectedNode.Nodes;
foreach( System.Windows.Forms.TreeNode myTreeNode in myNodeCollection)
{
if(!GetSubDirectory(myTreeNode.FullPath,myTreeNode))
{
MessageBox.Show("当前节点展开时,添加子节点出错!");
return;
}
}
treeView1.Update();
} /// <summary>
/// 某个节点展开时,给它的子节点增加子节点
/// </summary>
/// <param name="sender">事件触发者</param>
/// <param name="e">时间参数</param>
private void treeView1_AfterExpand(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
System.Windows.Forms.TreeNodeCollection myNodeCollection=e.Node.Nodes;
foreach( System.Windows.Forms.TreeNode myTreeNode in myNodeCollection)
{
if(!GetSubDirectory(myTreeNode.FullPath,myTreeNode))
{
MessageBox.Show("当前节点展开时,添加子节点出错!");
return;
}
}
treeView1.Update();
} /// <summary>
/// 取消
/// </summary>
/// <param name="sender">事件触发者</param>
/// <param name="e">时间参数</param>
private void button2_Click(object sender, System.EventArgs e)
{ newFilePath="";
this.Dispose();
} /// <summary>
/// 确定
/// </summary>
/// <param name="sender">事件触发者</param>
/// <param name="e">时间参数</param>
private void button1_Click(object sender, System.EventArgs e)
{
this.Dispose();
}
}
}