社区
C#
帖子详情
如何实现一个选择文件路径的对话框?
davidwee
2002-11-13 03:57:44
OpenFileDialog只能选择文件,如何让一个对话框只选择目录呢?
难道需要自己写一个么,如果那样的话,岂不是很麻烦?
...全文
1418
5
打赏
收藏
如何实现一个选择文件路径的对话框?
OpenFileDialog只能选择文件,如何让一个对话框只选择目录呢? 难道需要自己写一个么,如果那样的话,岂不是很麻烦?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
烈马狂生
2002-11-13
打赏
举报
回复
我上边提供的有误。
下面提供另一个:
///<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();
}
}
}
yarshray
2002-11-13
打赏
举报
回复
http://www.codeproject.com/cs/miscctrl/folderseldlg.asp
烈马狂生
2002-11-13
打赏
举报
回复
为什么不用SaveFileDialog 多么简单呀。
我就是这么用的。效果很好。
idiotzeng
2002-11-13
打赏
举报
回复
http://expert.csdn.net/Expert/topic/1155/1155973.xml?temp=.0625574
Dugu_Niu
2002-11-13
打赏
举报
回复
从旧贴中找找,多着呢
vc
选择
文件
路径
对话框
两种不同方式及打开指定
文件
夹
1,经常用到
文件
路径
选择
对话框
,但没有现成的类供使用,这里通过几个函数封装以不同的方式
实现
文件
路径
选择
; 2,打开指定
路径
的
文件
夹也很实用
python通过
对话框
实现
文件
或
文件
夹
路径
的
选择
并获得
路径
在通过python保存一些
文件
的时候 ,想要通过
对话框
的方式来添加
文件
路径
网上可以查到很多资料,但是如果要通过
对话框
的方式来添加
文件
夹
路径
却查了好久也没有查到,最后经过一番查找加理解,终于
实现
了,我猜没有查到的原因可能是需要
文件
夹的人比较少吧,大部分直接添加了
文件
路径
。 接下来介绍一下在python中如何通过
对话框
的方式获得
文件
和
文件
夹的
路径
首先导入thinter 然后一次打开
文件
夹
选择
的对话...
基于Threejs/Webgl三维实时数据&车辆
路径
导航功能 项目实战一
针对webgl的库threejs框架项目功能实战讲解实时数据功能:对生产设备设施、传感器、开关控制的实时数据和运行状态查看,在三维场景中实时数据和状态,根据报警级别显示不同设备颜色。车辆
路径
导航:工厂车辆位置坐标做定位监控,根据车辆定位坐标在三维场景中可以展现车辆实时位置分布、车辆行驶运行状态;同时也可以仿真模拟车辆运行轨迹。threejs 98版本开发环境(IDE) WebStorm 2019.2 版本
python
实现
对话框
文件
选择
以及
文件
路径
选择
python
实现
对话框
文件
选择
以及
文件
路径
选择
文章目录python
实现
对话框
文件
选择
以及
文件
路径
选择
效果展现二、步骤1.引入库2.创建对象3.调用方法接收
文件
返回4.全部完整代码总结 效果展现 示例:先给大家看效果,看看是不是你想要的效果。 这里是最终的效果图展示,大家可以看看是不是你需要的效果。 二、步骤 1.引入库 下面展示 代码片。 代码如下: import tkinter as tk from tkinter import filedialog 2.创建对象 代码如下: root=tk.
实现
Java中的
文件
选择
对话框
例如,在Windows系统上,
文件
选择
对话框
可能是
一个
标准的Windows
文件
选择
对话框
,而在Mac OS上可能是
一个
标准的Mac
文件
选择
对话框
。
文件
选择
对话框
是
一个
常见的用户界面组件,用于允许用户从计算机
文件
系统中
选择
文件
或目录。这将打开
一个
文件
选择
对话框
,允许用户
选择
一个
文件
。希望这篇文章能够帮助你理解如何在Java中
实现
文件
选择
对话框
,并提供了相应的源代码。然后,我们可以创建
一个
简单的Java应用程序,并在其中使用JFileChooser类来
实现
文件
选择
对话框
。最后,我们打印出
选择
的
文件
路径
。
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章