C# winform 组件---- folderBrowserDialog与openFileDialog(转)
vs2008 winform 的工具箱中有两个组件:folderBrowserDialog与openFileDialog.他们的作用如下:
folderBrowserDialog:打开一个浏览对话框,以便选取路经.
openFileDialog: 打开一个浏览对话框,以便选取一个文件名.
在实际操作中的应用如下:
private void button1_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
this.textBox1.Text = folderBrowserDialog1.SelectedPath;
}
private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
this.textBox2.Text = openFileDialog1.SafeFileName;
}
如果没有在窗体中拖入folderBrowserDialog与openFileDialog组件,代码也可以这样来写:
using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsApplication1
- {
- public partial class SelectFolder : Form
- {
- public SelectFolder()
- {
- InitializeComponent();
- }
- private void btnSelectPath_Click(object sender, EventArgs e)
- {
- FolderBrowserDialog path = new FolderBrowserDialog();
- path.ShowDialog();
- this.txtPath.Text = path.SelectedPath;
- }
- private void btnSelectFile_Click(object sender, EventArgs e)
- {
- OpenFileDialog file = new OpenFileDialog();
- file.ShowDialog();
- this.txtFile.Text = file.SafeFileName;
- }
- }
- }
[C#]Winform選擇目錄路徑(FolderBrowserDialog)與選擇檔案名稱(OpenFileDialog)的用法
最近寫winform的程式,剛好要用到這樣的功能
介紹如何利用FolderBrowserDialog與OpenFileDialog
來選擇目錄或檔案...
c#(winform)部分程式碼
SelectFolder.cs
01 |
<span style="display: none" id="1226045165047S"> </span>using System; |
02 |
using System.Collections.Generic; |
03 |
using System.ComponentModel; |
04 |
using System.Data; |
05 |
using System.Drawing; |
06 |
using System.Text; |
07 |
using System.Windows.Forms; |
08 |
09 |
namespace WindowsApplication1 |
10 |
{ |
11 |
public partial class SelectFolder : Form |
12 |
{ |
13 |
public SelectFolder() |
14 |
{ |
15 |
InitializeComponent(); |
16 |
} |
17 |
18 |
private void btnSelectPath_Click(object sender, EventArgs e) |
19 |
{ |
20 |
FolderBrowserDialog path = new FolderBrowserDialog(); |
21 |
path.ShowDialog(); |
22 |
this.txtPath.Text = path.SelectedPath; |
23 |
} |
24 |
25 |
private void btnSelectFile_Click(object sender, EventArgs e) |
26 |
{ |
27 |
OpenFileDialog file = new OpenFileDialog(); |
28 |
file.ShowDialog(); |
29 |
this.txtFile.Text = file.SafeFileName; |
30 |
} |
31 |
32 |
} |
33 |
} |
執行結果:
1.主畫面

2.選目錄

3.選檔案

參考網址:
http://www.codeproject.com/KB/cs/csFolderBrowseDialogEx.aspx
C# winform 组件---- folderBrowserDialog与openFileDialog(转)的更多相关文章
- 在WPF使用FolderBrowserDialog和OpenFileDialog
原文 在WPF使用FolderBrowserDialog和OpenFileDialog 相信习惯以前winform开发的朋友们都对FolderBrowserDialog和OpenFileDialog这 ...
- vs2017 winform 组件 -- 总结
1.ComboBox [下拉框] (1) 添加选项 this.[控件名].Items.Add("内容") (2)设置下拉框 自动完成 模式 和 数据源 this.[控件名].Au ...
- WinForm中的ListBox组件编程
ListBox组件是一个程序设计中经常使用到的组件,在Visual C#和Visual Basic .Net程序中使用这个组件,必须要在程序中导入.Net FrameWork SDK中名称空间Syst ...
- .net WinForm 的数据绑定
.net WinForm 的数据绑定相当灵活 http://www.cnblogs.com/ydong/archive/2006/04/22/381847.html 原来只知道 Control 类上的 ...
- FtpWebRequest与FtpWebResponse完成FTP操作
WebRequestMethods.Ftp类: 表示可与 FTP 请求一起使用的 FTP 协议方法的类型. AppendFile 表示要用于将文件追加到 FTP 服务器上的现有文件的 FTP ...
- c#第三方控件地址
原文:http://blog.csdn.net/wpcxyking/article/details/6249825 首先感谢博文原者,分享这么有价值的内容,特此感谢. DevExpress 出品 Dx ...
- C# 選擇本機檔案並上傳
參考自:http://www.dotblogs.com.tw/puma/archive/2008/11/07/5910.aspxhttp://www.codeproject.com/Articles/ ...
- VB.NET数据库编程基础教程
关键词:作者罗姗 众所周知,VB.NET自身并不具备对数据库进行操作的功能,它对数据库的处理是通过.NET FrameWork SDK中面向数据库编程的类库和微软的MDAC来实现的.其中,ADO. ...
- C#使用NanUI或ChromiumFx碰到的坑(一)
最近在花时间封装一个Razor模板+NanUI的Winform组件,发现了有个神奇地方,,由于需要使用CfxResourceHandler,用于把对cshtml文件的请求,编译成html并返回给CEF ...
随机推荐
- Android RecyclerView利用Glide加载大量图片into(Target)导致OOM异常
学过android的人应该都知道Glide是一个无比强大的图片加载库,它内部已经提供了很好的缓存机制供我们选择,我们只需一个参数调用即可(DiskCacheStrategy()),而不必像Univer ...
- ORA-02068,ORA-03135错误解决方法
今天查看了下ERP DB服务器 alter_<SID>.log日志,发现有个错误 Sat Sep 14 14:49:42 CST 2013 Error 2068 trapped in 2P ...
- [Java]Java分层概念
service是业务层 action层即作为控制器 DAO (Data Access Object) 数据访问 1.JAVA中Action层, Service层 ,modle层 和 Dao层的功能 ...
- Centos6.6 安装nfs网络文件系统
一.介绍 nfs网络文件系统的,大部分用在内网文件共享,比如,对集群上传文件做共享,经常用在图片部分,当然数据量大了还是要做分离,做为专门的接口比较好,介绍一下基本安装环境: 1)Cnetos6.6 ...
- HDU_1285_拓扑排序(优先队列)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- CAD得到自定义实体拖放夹点(com接口VB语言)
主要用到函数说明: MxDrawXCustomEvent::MxDrawXCustomEntity::getGripPoints 自定义实体事件,得到拖放夹点,详细说明如下: 参数 说明 LONGLO ...
- 【原】PHPExcel导出Excel
1.引入相关公共库PHPExcel 2.编写公共函数 public function exportExcel($excelTitle,$data,$filename='',$column_width= ...
- hdu 2084 数塔(简单dp)
题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...
- yum更换国内源及yum下载rpm包
一.yum更换国内源 运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 1.前往yum文件路径地址 [root@web1 ~]# cd /etc/yum.repos.d/ [root ...
- TortoiseGit配置密钥的方法
TortoiseGit 使用扩展名为ppk的密钥,而不是ssh-keygen生成的rsa密钥.使用命令ssh-keygen -C "邮箱地址" -t rsa产生的密钥在Tortoi ...