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 ...
随机推荐
- node.js安装步骤
首先这是node.js的官网:https://nodejs.org/en/ 截至2017年12月9日,node更新在8.9.3该版本,建议开发人员下载6.0以上版本,8以上不是很稳定! 如果有其他需 ...
- 清瘦的记录者: 一个比dbutils更小巧、好用的的持久化工具
https://gitee.com/bitprince/memory 1. 概述 1.1 连接.语句和结果集 从JDBC的规范上看,其对数据访问层有相当简洁的抽象:1.连接(connection) 2 ...
- jQuery——插件制作
1.$.fn.extend:扩展 jQuery 元素集来提供新的方法(通常用来制作插件),使用时是$('选择器').方法 2.$.extend:扩展jQuery对象本身,用来在jQuery命名空间上增 ...
- C# 打开模态对话框 和打开文件夹
C# 打开另一个窗体,(模态对话框) Form1 frm= new Form1(); //创建对象 DialogResult retServer = frm.ShowDialog(); //模式对话框 ...
- JavaScript ES 数组系列
正文从这开始- ECMAScript 5.1 中提供的数组方法 其中部分方法,ECMAScript 3 就出现了,但是本文不再细分. ECMA-262/5.1 规范:https://www.ecma- ...
- C3P0数据库连接池使用方法
一.应用程序直接获取数据库连接的缺点 用户每次请求都需要向数据库获得链接,而数据库创建连接通常需要消耗相对较大的资源,创建时间也较长.假设网站一天10万访问量,数据库服务器就需要创建10万次连接,极大 ...
- css3 animation 中的 steps
steps Specifies a stepping function, described above, taking two parameters. The first parameter spe ...
- 零基础转行Linux云计算运维工程师获得20万年薪的超级学习技巧
云计算概念一旦产生便一发不可收拾,成为移动互联网时代最为火热的行业之一.国内各大互联网公司例如阿里.腾讯.百度.网易等纷纷推出自己的云计算产品,3月10日,腾讯云0.01元投标时间更是让云计算在普罗大 ...
- OprenCV学习之路一:将彩色图片转换成灰度图
//将一张彩色图片转成灰度图: //////////////////////////// #include<cv.h> #include<cvaux.h> #include&l ...
- POJ3984——迷宫问题
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31616 Accepted: 18100 Descriptio ...